From 631c4e5bc999d94b58110ba4aa16dd608b846340 Mon Sep 17 00:00:00 2001 From: Christian Heinrich Date: Sun, 19 Apr 2020 07:03:33 +1000 Subject: [PATCH] Support Python 3 Signed-off-by: Christian Heinrich --- python/stathat.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/python/stathat.py b/python/stathat.py index 9b126ab..9dc878f 100644 --- a/python/stathat.py +++ b/python/stathat.py @@ -1,12 +1,13 @@ -import urllib -import urllib2 +from urllib.parse import urlencode +from urllib.request import Request, urlopen class StatHat: def http_post(self, path, data): - pdata = urllib.urlencode(data) - req = urllib2.Request('http://api.stathat.com' + path, pdata) - resp = urllib2.urlopen(req) + pdata = urlencode(data) + pdata = pdata.encode('ascii') + req = Request('http://api.stathat.com' + path, pdata) + resp = urlopen(req) return resp.read() def post_value(self, user_key, stat_key, value, timestamp=None):