changeset 38:6f85bedf9966

Authenticate properly in Python 3
author Daniel O'Connor <darius@dons.net.au>
date Wed, 02 Dec 2020 11:19:50 +1030
parents 4f9a79f733ff
children 1a87c79cf103
files adslstats.py
diffstat 1 files changed, 3 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/adslstats.py	Sat Nov 21 10:31:42 2020 +1030
+++ b/adslstats.py	Wed Dec 02 11:19:50 2020 +1030
@@ -151,18 +151,18 @@
     token = bs.head.find(lambda tag: tag.has_attr('name') and tag['name'] == 'CSRFtoken')['content']
     #print('Got CSRF token ' + token)
 
-    usr = srp.User(username, password, hash_alg = srp.SHA256, ng_type = srp.NG_2048)
+    usr = srp.User(username.encode('utf-8'), password.encode('utf-8'), hash_alg = srp.SHA256, ng_type = srp.NG_2048)
     uname, A = usr.start_authentication()
 
     req = mechanize.Request(base + '/authenticate', data = urllib.parse.urlencode({'CSRFtoken' : token, 'I' : uname, 'A' : binascii.hexlify(A)}))
     r = br.open(req)
-    j = json.decoder.JSONDecoder().decode(r.read())
+    j = json.decoder.JSONDecoder().decode(r.read().decode('utf-8'))
     #print('Sent challenge, got ' + str(j))
 
     M = usr.process_challenge(binascii.unhexlify(j['s']), binascii.unhexlify(j['B']))
     req = mechanize.Request(base + '/authenticate', data = urllib.parse.urlencode({'CSRFtoken' : token, 'M' : binascii.hexlify(M)}))
     r = br.open(req)
-    j = json.decoder.JSONDecoder().decode(r.read())
+    j = json.decoder.JSONDecoder().decode(r.read().decode('utf-8'))
     #print('Got response ' + str(j))
 
     usr.verify_session(binascii.unhexlify(j['M']))