idna-ssl

1.1.0 · abandoned · verified Sun Apr 12

The `idna-ssl` library provides a patch for Python's standard `ssl.match_hostname` function to correctly support Unicode (IDNA) domains. It aims to offer backward compatibility for older Python versions (pre-3.7) where `ssl.match_hostname` had significant issues with internationalized domain names, and to address lingering IDNA2008 compliance problems even in later Python releases. The library's current version is 1.1.0, released in July 2018. The project's GitHub repository has been archived and is read-only since October 2020, indicating it is no longer actively maintained.

Warnings

Install

Imports

Quickstart

The `patch_match_hostname()` function needs to be imported and called early in your application's lifecycle to apply the necessary fix globally. The example demonstrates its use with `aiohttp` to access a Unicode domain, which would otherwise fail hostname verification on affected Python versions.

from idna_ssl import patch_match_hostname
import asyncio
import aiohttp

# Apply the patch globally as early as possible in your application
patch_match_hostname()

# Example usage with aiohttp accessing an IDNA domain
URL = 'https://цфоут.мвд.рф/news/item/8065038/'

async def main():
    async with aiohttp.ClientSession() as session:
        async with session.get(URL) as response:
            print(f"Status: {response.status}")
            print(f"Content-Type: {response.headers.get('Content-Type')}")

if __name__ == '__main__':
    # This example requires Python 3.7+ for asyncio.run()
    # For older Python versions, use loop = asyncio.get_event_loop(); loop.run_until_complete(main())
    try:
        asyncio.run(main())
    except RuntimeError:
        loop = asyncio.get_event_loop()
        loop.run_until_complete(main())

view raw JSON →