Skip to content

Commit

Permalink
encode and decode for python3
Browse files Browse the repository at this point in the history
  • Loading branch information
knorth55 committed Mar 24, 2023
1 parent c4b4d43 commit 557c6d4
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/roswww/roswww_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import base64
import functools
import socket
import sys
import tornado.ioloop # rosbridge installs tornado
import tornado.web
import yaml
Expand All @@ -59,12 +60,16 @@ def _request_auth(handler):
def new_f(*args):
handler = args[0]
auth_header = handler.request.headers.get('Authorization')

if auth_header is None:
return _request_auth(handler)
if not auth_header.startswith('Basic '):
return _request_auth(handler)

auth_decoded = base64.decodestring(auth_header.split(' ', 1)[1])
if sys.version_info.major >= 3:
auth_decoded = base64.decodestring(auth_header.split(' ', 1)[1].encode('ascii')).decode('utf-8')
else:
auth_decoded = base64.decodestring(auth_header.split(' ', 1)[1])
username, password = auth_decoded.split(':', 1)

if auth(username, password):
Expand Down

0 comments on commit 557c6d4

Please sign in to comment.