aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/authentication.py
diff options
context:
space:
mode:
Diffstat (limited to 'rest_framework/authentication.py')
-rw-r--r--rest_framework/authentication.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/rest_framework/authentication.py b/rest_framework/authentication.py
index 30c78ebc..15e531bf 100644
--- a/rest_framework/authentication.py
+++ b/rest_framework/authentication.py
@@ -3,7 +3,11 @@ Provides a set of pluggable authentication policies.
"""
from django.contrib.auth import authenticate
-from django.utils.encoding import smart_unicode, DjangoUnicodeDecodeError
+from django.utils.encoding import DjangoUnicodeDecodeError
+try:
+ from django.utils.encoding import smart_text
+except ImportError:
+ from django.utils.encoding import smart_unicode as smart_text
from rest_framework import exceptions
from rest_framework.compat import CsrfViewMiddleware
from rest_framework.authtoken.models import Token
@@ -36,13 +40,13 @@ class BasicAuthentication(BaseAuthentication):
auth = request.META['HTTP_AUTHORIZATION'].split()
if len(auth) == 2 and auth[0].lower() == "basic":
try:
- auth_parts = base64.b64decode(auth[1]).partition(':')
+ auth_parts = base64.b64decode(auth[1].encode('iso-8859-1')).decode('iso-8859-1').partition(':')
except TypeError:
return None
try:
- userid = smart_unicode(auth_parts[0])
- password = smart_unicode(auth_parts[2])
+ userid = smart_text(auth_parts[0])
+ password = smart_text(auth_parts[2])
except DjangoUnicodeDecodeError:
return None