mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-28 17:09:59 +03:00
basicauth: add fallback to latin-1 encoding if utf-8 fails
This commit is contained in:
parent
2394a50b59
commit
f256cd2dab
|
@ -74,7 +74,11 @@ class BasicAuthentication(BaseAuthentication):
|
||||||
raise exceptions.AuthenticationFailed(msg)
|
raise exceptions.AuthenticationFailed(msg)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
auth_parts = base64.b64decode(auth[1]).decode('utf-8').partition(':')
|
try:
|
||||||
|
auth_decoded = base64.b64decode(auth[1]).decode('utf-8')
|
||||||
|
except UnicodeDecodeError:
|
||||||
|
auth_decoded = base64.b64decode(auth[1]).decode('latin-1')
|
||||||
|
auth_parts = auth_decoded.partition(':')
|
||||||
except (TypeError, UnicodeDecodeError, binascii.Error):
|
except (TypeError, UnicodeDecodeError, binascii.Error):
|
||||||
msg = _('Invalid basic header. Credentials not correctly base64 encoded.')
|
msg = _('Invalid basic header. Credentials not correctly base64 encoded.')
|
||||||
raise exceptions.AuthenticationFailed(msg)
|
raise exceptions.AuthenticationFailed(msg)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user