Consistent utf string

master
Bob Mottram 2019-07-03 20:15:42 +01:00
parent f5df29cda9
commit 8ad7ee5ff2
2 changed files with 4 additions and 4 deletions

View File

@ -36,7 +36,7 @@ def createBasicAuthHeader(nickname: str,password: str) -> str:
"""This is only used by tests
"""
authStr=nickname.replace('\n','')+':'+password.replace('\n','')
return 'Basic '+base64.b64encode(authStr.encode('utf8')).decode('utf8')
return 'Basic '+base64.b64encode(authStr.encode('utf-8')).decode('utf-8')
def authorizeBasic(baseDir: str,authHeader: str) -> bool:
"""HTTP basic auth
@ -44,7 +44,7 @@ def authorizeBasic(baseDir: str,authHeader: str) -> bool:
if ' ' not in authHeader:
return False
base64Str = authHeader.split(' ')[1].replace('\n','')
plain = base64.b64decode(base64Str).decode('utf8')
plain = base64.b64decode(base64Str).decode('utf-8')
if ':' not in plain:
return False
nickname = plain.split(':')[0]

View File

@ -177,10 +177,10 @@ class PubServer(BaseHTTPRequestHandler):
filename=self.server.baseDir+self.path
if os.path.isfile(filename):
self._set_headers('application/json')
with open(filename, 'r', encoding='utf8') as File:
with open(filename, 'r', encoding='utf-8') as File:
content = File.read()
contentJson=json.loads(content)
self.wfile.write(json.dumps(contentJson).encode('utf8'))
self.wfile.write(json.dumps(contentJson).encode('utf-8'))
else:
if self.server.debug:
print('DEBUG: GET Unknown file')