Mercurial > templog
comparison py/uploader.py @ 231:e39ed85d87a5
fix a few python3 issues
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sat, 11 Apr 2015 00:16:05 +0800 |
parents | 185621f47040 |
children | 19569cb5ed46 |
comparison
equal
deleted
inserted
replaced
230:185621f47040 | 231:e39ed85d87a5 |
---|---|
42 return tosend | 42 return tosend |
43 | 43 |
44 @asyncio.coroutine | 44 @asyncio.coroutine |
45 def send(self, tosend): | 45 def send(self, tosend): |
46 js = json.dumps(tosend) | 46 js = json.dumps(tosend) |
47 js_enc = binascii.b2a_base64(zlib.compress(js)) | 47 js_enc = binascii.b2a_base64(zlib.compress(js.encode())) |
48 mac = hmac.new(config.HMAC_KEY, js_enc).hexdigest() | 48 mac = hmac.new(config.HMAC_KEY.encode(), js_enc).hexdigest() |
49 send_data = {'data': js_enc, 'hmac': mac} | 49 send_data = {'data': js_enc, 'hmac': mac} |
50 r = yield from asyncio.wait_for(aiohttp.request('post', config.UPDATE_URL, data=send_data), 60) | 50 r = yield from asyncio.wait_for(aiohttp.request('post', config.UPDATE_URL, data=send_data), 60) |
51 result = yield from asyncio.wait_for(r.text(), 60) | 51 result = yield from asyncio.wait_for(r.text(), 60) |
52 if result != 'OK': | 52 if result != 'OK': |
53 raise Exception("Server returned %s" % result) | 53 raise Exception("Server returned %s" % result) |
60 nreadings = len(readings) | 60 nreadings = len(readings) |
61 yield from self.send(tosend) | 61 yield from self.send(tosend) |
62 readings = None | 62 readings = None |
63 D("Sent updated %d readings" % nreadings) | 63 D("Sent updated %d readings" % nreadings) |
64 except Exception as e: | 64 except Exception as e: |
65 EX("Error in uploader: %s" % str(e)) | 65 E("Error in uploader: %s" % str(e)) |
66 finally: | 66 finally: |
67 if readings is not None: | 67 if readings is not None: |
68 self.server.pushfront(readings) | 68 self.server.pushfront(readings) |