# HG changeset patch # User Matt Johnston # Date 1406303735 -28800 # Node ID e3b85f9fbb03eac351896520b0514a071d5c970b # Parent 4d82099d1fe006c5d5e227d835e01ed4cc42b394# Parent 4ddc5d5cab3714baadf95f4ffd73b998f6348790 merge diff -r 4ddc5d5cab37 -r e3b85f9fbb03 py/requirements.txt --- a/py/requirements.txt Fri Jul 04 21:31:34 2014 +0800 +++ b/py/requirements.txt Fri Jul 25 23:55:35 2014 +0800 @@ -1,7 +1,17 @@ argparse==1.2.1 -gevent==1.0rc2 -greenlet==0.4.0 +wsgiref==0.1.2 + +# sha256: v6nYRtuRp9i2o26HNT7tZBx-Pn0L-guZdXltIn8ttOs +gevent==1.0 + +# sha256: sWDlVqIuFrrj8_Y__OeJhoLIA82JZFcZL3tU_nT-mR4 +greenlet==0.4.2 + +# sha256: I9pYnJH1nLfGRNXOXfU51Eg0G9R5kX1t3pc_guJxkUc lockfile==0.9.1 + +# sha256: FmX7Fr_q5y8Wqi3kC8dWYUWL1Ccxp9RjqRGo1er5bAs python-daemon==1.6 -smbus==1.1 -wsgiref==0.1.2 + +# sha256: NkiAJJLpVf_rKPbauGStcUBZ9UOL9nmNgvnUd8ZmrKM +requests==2.3.0 diff -r 4ddc5d5cab37 -r e3b85f9fbb03 py/uploader.py --- a/py/uploader.py Fri Jul 04 21:31:34 2014 +0800 +++ b/py/uploader.py Fri Jul 25 23:55:35 2014 +0800 @@ -2,10 +2,10 @@ import hmac import zlib import binascii -import urllib -import urllib2 +import logging import gevent +import requests import config from utils import L,D,EX,W,E @@ -16,6 +16,9 @@ gevent.Greenlet.__init__(self) self.server = server + requests_log = logging.getLogger("requests") + requests_log.setLevel(logging.WARNING) + def _run(self): gevent.sleep(5) while True: @@ -44,9 +47,9 @@ js = json.dumps(tosend) js_enc = binascii.b2a_base64(zlib.compress(js)) mac = hmac.new(config.HMAC_KEY, js_enc).hexdigest() - url_data = urllib.urlencode( {'data': js_enc, 'hmac': mac} ) - con = urllib2.urlopen(config.UPDATE_URL, url_data) - result = con.read(100) + send_data = {'data': js_enc, 'hmac': mac} + r = requests.post(config.UPDATE_URL, data=send_data) + result = r.text if result != 'OK': raise Exception("Server returned %s" % result) @@ -58,7 +61,7 @@ self.send(tosend) readings = None D("Sent updated %d readings" % nreadings) - except urllib2.HTTPError, e: + except requests.exceptions.RequestException, e: E("Error in uploader: %s" % str(e)) except Exception, e: EX("Error in uploader: %s" % str(e))