-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Description
Long story short
The http client does have some problem, when the last part of the hostname becomes too long (but in the valid length of an DNS part)
To reproduce, choose a hostname with 60 bytes in the last part of DNS, add a port and try to access the url:
https://host-12345678901234567890123456789012345678901234567890-name:8888/
Note that the hostname is 60 octets, but hostname with port is 65 octets
Expected behaviour
should work with all valid hostnames (a part can have a length of 63 octets)
Actual behaviour
does not work when the last part of a hostname together with the optional port exceeds 63 octets.
Steps to reproduce
Run the following script. It should print "can not connect". Instead it raises
UnicodeError: label too long
UnicodeError: encoding with 'idna' codec failed (UnicodeError: label too long)
ValueError: URL has an invalid label.
import asyncio
import aiohttp
url = "https://host-12345678901234567890123456789012345678901234567890-name:8888/"
#url = "https://fooooo:8888/"
async def test_bug(session):
try:
async with session.get(url) as resp:
pass
except aiohttp.errors.ClientOSError:
print("can not connect")
loop = asyncio.get_event_loop()
with aiohttp.ClientSession(loop=loop) as session:
loop.run_until_complete(test_bug(session))
Your environment
MacOS 10.9, Python 3.5
using aiohttp-0.21.5