-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Client can not handle hostnames with 63 bytes when a port is given in the url #1044
Comments
The following patch agains 0.21.5 fixes the problem for me. diff --git a/build-env/lib/python3.5/site-packages/aiohttp/client_reqrep.py b/build-env/lib/python3.5/site-packages/aiohttp/client_reqrep.py
index 68d0ea5..14e2640 100644
--- a/build-env/lib/python3.5/site-packages/aiohttp/client_reqrep.py
+++ b/build-env/lib/python3.5/site-packages/aiohttp/client_reqrep.py
@@ -117,7 +117,7 @@ class ClientRequest:
# check domain idna encoding
try:
- netloc = netloc.encode('idna').decode('utf-8')
+ # netloc = netloc.encode('idna').decode('utf-8')
host = host.encode('idna').decode('utf-8')
except UnicodeError:
raise ValueError('URL has an invalid label.') I really do not understand why the netloc is checked here, as it can contain the port. IDNA encoding should probably only be executed on the hostname part without the port. |
Good catch! |
Well, I don't know when yarl will be ready but a fix for this particular case is trivial. |
… the url aio-libs#1044 I handled by reconstructing url string. And I used function make_netlog in client_reqrep.py
… the url aio-libs#1044 I handled by reconstructing url string. And I used function make_netlog in client_reqrep.py
… the url aio-libs#1044 #last Message############################## I handled by reconstructing url string. And I used function make_netlog in client_reqrep.py ######################################### I added missing test functions. It would verify by these methods
… the url aio-libs#1044 #last Message############################## I handled by reconstructing url string. And I used function make_netlog in client_reqrep.py ######################################### I added missing test functions. It would verify by these methods
* Implement proxy support for ClientSession.ws_connect #1025 Maybe.. Done.. I didn't check by Test mock.... But you said this would beeee OK... Hopefully ^^ This is my first commit. * Client can not handle hostnames with 63 bytes when a port is given in the url #1044 I handled by reconstructing url string. And I used function make_netlog in client_reqrep.py * Client can not handle hostnames with 63 bytes when a port is given in the url #1044 I handled by reconstructing url string. And I used function make_netlog in client_reqrep.py * Client can not handle hostnames with 63 bytes when a port is given in the url #1044 #last Message############################## I handled by reconstructing url string. And I used function make_netlog in client_reqrep.py ######################################### I added missing test functions. It would verify by these methods * Client can not handle hostnames with 63 bytes when a port is given in the url #1044 #last Message############################## I handled by reconstructing url string. And I used function make_netlog in client_reqrep.py ######################################### I added missing test functions. It would verify by these methods * Fix the code format. They all checked by flake8 * Fix the code format. @ client_reqrep.py They all checked by flake8
Fixed by #1088 |
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.
Your environment
MacOS 10.9, Python 3.5
using aiohttp-0.21.5
The text was updated successfully, but these errors were encountered: