-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
HTTPDigestAuth fails on non-latin credentials #6102
Comments
Hi @ondratu, Could you please clarify what you believe is wrong in this case? 'Ondřej'.encode('utf-8') == b'Ond\xc5\x99ej'
>>> True It's not clear what other value you'd be expecting. |
Hmm, on closer inspection this does appear to be a bug. We're using the bytes username as an argument to format our string for the header. This causes the full literal When not encoding the auth/password, we get this: Traceback (most recent call last):
File "/Users/nateprewitt/Work/OpenSource/requests/test.py", line 3, in <module>
r = requests.get('https://httpbin.org/digest-auth/auth/Ondřej/heslíčko', auth=h)
File "/Users/nateprewitt/Work/OpenSource/requests/requests/api.py", line 73, in get
return request("get", url, params=params, **kwargs)
[...]
File "/Users/nateprewitt/.pyenv/versions/3.10.3/lib/python3.10/http/client.py", line 1323, in _send_request
self.putheader(hdr, value)
File "/Users/nateprewitt/.pyenv/versions/3.10.3/lib/python3.10/site-packages/urllib3/connection.py", line 224, in putheader
_HTTPConnection.putheader(self, header, *values)
File "/Users/nateprewitt/.pyenv/versions/3.10.3/lib/python3.10/http/client.py", line 1255, in putheader
values[i] = one_value.encode('latin-1')
UnicodeEncodeError: 'latin-1' codec can't encode character '\u0159' in position 20: ordinal not in range(256) Fixing this is unfortunately somewhat complicated for a couple reasons: 1.) Users expect the output of I don't believe we can ever format this correctly in Python 3 with the current behavior though. I'll need to look more tomorrow, but we may consider a behavior change if |
Resolution for the issue psf#6102 Now, If a username and password are passed already encoded, they will not be affected by being expected as a string. In this case, the function will encode the string-formatted attributes into bytes using the latin-1 charset by default due to convention.
Resolution for the issue psf#6102 Now, If a username and password are passed already encoded, they will not be affected by being expected as a string. In this case, the function will encode the string-formatted attributes into bytes using the latin-1 charset by default due to convention.
Hi all, I saw the exception above, and knew immediately a quick test to see if charset encoding would fix it:
I realize exposing encoding in the function signatures will have a ripple effect, but I don't think the Requested change: add encoding kwarg to
One line fix and I'm good to go.... hopefully you can include in an upcoming release. Password policy changes are now more frequently including Unicode. |
There was issue reported, which is closed with bad results.
requests/requests/auth.py
Lines 59 to 63 in 4f6c018
Don't pass unicode strings in the arguments, but use UTF8 bytes instead.
Originally posted by @D-stefaang in #5089 (comment)
But this is wrong! When i try to set user 'Ondřej' with this advice, requests send bad string:
creates header starts with wrong username!
The text was updated successfully, but these errors were encountered: