diff --git a/rest_framework/authentication.py b/rest_framework/authentication.py index 1e30728d3..223184189 100644 --- a/rest_framework/authentication.py +++ b/rest_framework/authentication.py @@ -74,7 +74,7 @@ class BasicAuthentication(BaseAuthentication): raise exceptions.AuthenticationFailed(msg) try: - auth_parts = base64.b64decode(auth[1]).decode(HTTP_HEADER_ENCODING).partition(':') + auth_parts = base64.b64decode(auth[1]).decode('utf-8').partition(':') except (TypeError, UnicodeDecodeError, binascii.Error): msg = _('Invalid basic header. Credentials not correctly base64 encoded.') raise exceptions.AuthenticationFailed(msg) diff --git a/tests/authentication/test_authentication.py b/tests/authentication/test_authentication.py index 37e265e17..b4cbe856c 100644 --- a/tests/authentication/test_authentication.py +++ b/tests/authentication/test_authentication.py @@ -85,7 +85,7 @@ class BasicAuthTests(TestCase): self.csrf_client = APIClient(enforce_csrf_checks=True) self.username = 'john' self.email = 'lennon@thebeatles.com' - self.password = 'password' + self.password = 'pässwörd' self.user = User.objects.create_user( self.username, self.email, self.password ) @@ -94,7 +94,7 @@ class BasicAuthTests(TestCase): """Ensure POSTing json over basic auth with correct credentials passes and does not require CSRF""" credentials = ('%s:%s' % (self.username, self.password)) base64_credentials = base64.b64encode( - credentials.encode(HTTP_HEADER_ENCODING) + credentials.encode('utf-8') ).decode(HTTP_HEADER_ENCODING) auth = 'Basic %s' % base64_credentials response = self.csrf_client.post( @@ -108,7 +108,7 @@ class BasicAuthTests(TestCase): """Ensure POSTing form over basic auth with correct credentials passes and does not require CSRF""" credentials = ('%s:%s' % (self.username, self.password)) base64_credentials = base64.b64encode( - credentials.encode(HTTP_HEADER_ENCODING) + credentials.encode('utf-8') ).decode(HTTP_HEADER_ENCODING) auth = 'Basic %s' % base64_credentials response = self.csrf_client.post(