Skip to content

Commit 69f33ee

Browse files
Allow cookie authentication to work with Python 3.5
The json module started understanding bytes in Python 3.6 (with an heuristic on which Unicode encoding the bytes are using). We don't ufficially support Python 3.5, but since it's an easy fix and we know better than the heuristic the encoding (UTF-8, since everything is ASCII, really), let's decode explicitly.
1 parent 3401a2a commit 69f33ee

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

cms/server/contest/authentication.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ def log_failed_attempt(msg, *args):
150150
timestamp)
151151

152152
return (participation,
153-
json.dumps([username, password, make_timestamp(timestamp)]))
153+
json.dumps([username, password, make_timestamp(timestamp)])
154+
.encode("utf-8"))
154155

155156

156157
class AmbiguousIPAddress(Exception):
@@ -316,7 +317,7 @@ def _authenticate_request_from_cookie(sql_session, contest, timestamp, cookie):
316317

317318
# Parse cookie.
318319
try:
319-
cookie = json.loads(cookie)
320+
cookie = json.loads(cookie.decode("utf-8"))
320321
username = cookie[0]
321322
password = cookie[1]
322323
last_update = make_datetime(cookie[2])
@@ -357,4 +358,5 @@ def log_failed_attempt(msg, *args):
357358
timestamp)
358359

359360
return (participation,
360-
json.dumps([username, password, make_timestamp(timestamp)]))
361+
json.dumps([username, password, make_timestamp(timestamp)])
362+
.encode("utf-8"))

0 commit comments

Comments
 (0)