Skip to content

Commit

Permalink
Add Python 3 support to _get_user().
Browse files Browse the repository at this point in the history
  • Loading branch information
berkerpeksag committed Jul 8, 2015
1 parent 5f3dc8e commit 117ef10
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions gunicorn/glogging.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import traceback

from gunicorn import util
from gunicorn.six import string_types
from gunicorn.six import PY3, string_types


# syslog facility codes
Expand Down Expand Up @@ -378,10 +378,13 @@ def _get_user(self, environ):
auth = http_auth.split(" ", 1)
if len(auth) == 2:
try:
auth = base64.b64decode(auth[1].strip()).split(":", 1)
except TypeError:
auth = base64.b64decode(auth[1].strip())
if PY3: # b64decode returns a byte string in Python 3
auth = auth.decode('utf-8')
auth = auth.split(":", 1)
except TypeError as exc:
self.debug("Couldn't get username: %s", exc)
return user
if len(auth) == 2:
user = auth[0]
return user

0 comments on commit 117ef10

Please sign in to comment.