You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Originally reported in Requests (psf/requests#6643) but also applicable here, : is a valid character in a path per RFC3986. However, if a path is used in urllib3 where the path starts with // then urllib3 interprets this as a scheme-less host and attempts to parse the hostname and port but the part after the : may not be an integer.
Environment
Describe your environment.
At least, paste here the output of:
If you have a server running on that port, a 200 OK, otherwise a connection error.
Actual Behavior
File "/home/sigmavirus24/sandbox/requests/.tox/py312/lib/python3.12/site-packages/urllib3/util/url.py", line 425, in parse_url
host, port = _HOST_PORT_RE.match(host_port).groups() # type: ignore[union-attr]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'groups'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/sigmavirus24/sandbox/requests/.tox/py312/lib/python3.12/site-packages/urllib3/poolmanager.py", line 444, in urlopen
response = conn.urlopen(method, u.request_uri, **kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/sigmavirus24/sandbox/requests/.tox/py312/lib/python3.12/site-packages/urllib3/connectionpool.py", line 711, in urlopen
parsed_url = parse_url(url)
^^^^^^^^^^^^^^
File "/home/sigmavirus24/sandbox/requests/.tox/py312/lib/python3.12/site-packages/urllib3/util/url.py", line 451, in parse_url
raise LocationParseError(source_url) from e
urllib3.exceptions.LocationParseError: Failed to parse: //v:h
Part of this is that u.request_uri is properly parsed and returned as //v:h but ConnectionPool.urlopen seems to be doing the same thing that PoolManager.urlopen does and the thing that PoolManager.urlopen is trying to delegate to it - i.e., it:
If, however, we can (as early as possible) normalize the URL then we'll be in a better place. For example, this doesn't happen if you do this on the ConnectionPool level directly:
>>> connpool = urllib3.HTTPConnectionPool(host='localhost', port=10000)
>>> connpool.urlopen(method='GET', url='http://localhost:10000//v:h')
...
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=10000): Max retries exceeded with url: http://localhost:10000//v:h (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fcb11ad7020>: Failed to establish a new connection: [Errno 111] Connection refused'))
And so I think that in PoolManager specifically, we need to trim those leading /. There are a few ways to do this:
I'm also worried about how this is handled in when handling redirects in the retry logic (e.g., server returns a Location: //v:h or Location: //host:port//v:h but I haven't investigated that
Subject
Originally reported in Requests (psf/requests#6643) but also applicable here,
:
is a valid character in a path per RFC3986. However, if a path is used in urllib3 where the path starts with//
then urllib3 interprets this as a scheme-less host and attempts to parse the hostname and port but the part after the:
may not be an integer.Environment
Describe your environment.
At least, paste here the output of:
Steps to Reproduce
Expected Behavior
If you have a server running on that port, a 200 OK, otherwise a connection error.
Actual Behavior
Part of this is that
u.request_uri
is properly parsed and returned as//v:h
butConnectionPool.urlopen
seems to be doing the same thing thatPoolManager.urlopen
does and the thing thatPoolManager.urlopen
is trying to delegate to it - i.e., it:urllib3/src/urllib3/connectionpool.py
Line 711 in d4ffa29
urllib3/src/urllib3/util/url.py
Line 425 in d4ffa29
If, however, we can (as early as possible) normalize the URL then we'll be in a better place. For example, this doesn't happen if you do this on the ConnectionPool level directly:
And so I think that in PoolManager specifically, we need to trim those leading
/
. There are a few ways to do this:The text was updated successfully, but these errors were encountered: