# HG changeset patch # User Daniel O'Connor # Date 1606870190 -37800 # Node ID 6f85bedf99662001b7e8318e585be99bd947b605 # Parent 4f9a79f733ffb41a2e27ebca564c33b052485152 Authenticate properly in Python 3 diff -r 4f9a79f733ff -r 6f85bedf9966 adslstats.py --- 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']))