Skip to content
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

Support '/' character in HTTP password #105

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kristapsk
Copy link

It should be callers responsibility to properly encode URL.

This will unquote any %.., but is especially important for /, due to how urllib.parse.urlparse() works.

>>> import urllib.parse as urlparse
>>> url = urlparse.urlparse('http://user:pwdwith/slash@127.0.0.1:8332')
>>> print (url.username, url.password, url.hostname, url.port)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.8/urllib/parse.py", line 177, in port
    raise ValueError(message) from None
ValueError: Port could not be cast to integer value as 'pwdwith'
>>> from requests.utils import quote
>>> url = urlparse.urlparse('http://user:{}@127.0.0.1:8332'.format(quote('pwdwith/slash', safe='')))
>>> print (url.username, url.password, url.hostname, url.port)
user pwdwith%2Fslash 127.0.0.1 8332
>>> print (url.username, urlparse.unquote(url.password), url.hostname, url.port)
user pwdwith/slash 127.0.0.1 8332

Will not work with Python2 as urlparse module does no thave unquote(). But Python2 is long time EOL and should not be used anyway.

It should be callers responsibility to properly encode URL.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant