From c6a3bfb57b44e2b540401dc1b3578c780d7d9066 Mon Sep 17 00:00:00 2001 From: Roel Baardman Date: Thu, 1 Feb 2018 09:06:16 +0100 Subject: [PATCH 1/2] Backport PyTado to Python2, using urllib2 --- PyTado/interface.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/PyTado/interface.py b/PyTado/interface.py index e1b58bf..ce16328 100755 --- a/PyTado/interface.py +++ b/PyTado/interface.py @@ -5,9 +5,11 @@ import logging import json import datetime -import urllib.request -import urllib.parse -import urllib.error +#import urllib.request +#import urllib.parse +#import urllib.error +import urllib2 +import urllib from http.cookiejar import CookieJar @@ -41,7 +43,7 @@ def _mobile_apiCall(self, cmd): cmd) url = '%s%s' % (self.mobi2url, cmd) - req = urllib.request.Request(url, headers=self.headers) + req = urllib2.urlopen(url, headers=self.headers) response = self.opener.open(req) str_response = response.read().decode('utf-8') @@ -73,9 +75,8 @@ def _apiCall(self, cmd, method="GET", data=None, plain=False): method, cmd, headers, data) url = '%s%i/%s' % (self.api2url, self.id, cmd) - req = urllib.request.Request(url, + req = urllib2.Request(url, headers=headers, - method=method, data=data) response = self.opener.open(req) @@ -119,9 +120,9 @@ def _refresh_token(self): 'scope' : 'home.user', 'refresh_token' : self.refresh_token} # pylint: disable=R0204 - data = urllib.parse.urlencode(data) + data = urllib.urlencode(data) url = url + '?' + data - req = urllib.request.Request(url, data=json.dumps({}).encode('utf8'), method='POST', + req = urllib2.urlopen(url, data=json.dumps({}).encode('utf8'), method='POST', headers={'Content-Type': 'application/json', 'Referer' : 'https://my.tado.com/'}) @@ -145,9 +146,9 @@ def _loginV2(self, username, password): 'scope' : 'home.user', 'username' : username} # pylint: disable=R0204 - data = urllib.parse.urlencode(data) + data = urllib.urlencode(data) url = url + '?' + data - req = urllib.request.Request(url, data=json.dumps({}).encode('utf8'), method='POST', + req = urllib2.Request(url, data=json.dumps({}).encode('utf8'), #method='POST', headers={'Content-Type': 'application/json', 'Referer' : 'https://my.tado.com/'}) @@ -167,7 +168,7 @@ def getMe(self): # pylint: disable=C0103 url = 'https://my.tado.com/api/v2/me' - req = urllib.request.Request(url, headers=self.headers) + req = urllib2.Request(url, headers=self.headers) response = self.opener.open(req) str_response = response.read().decode('utf-8') data = json.loads(str_response) @@ -286,8 +287,8 @@ def __init__(self, username, password): # pylint: disable=C0103 cj = CookieJar() - self.opener = urllib.request.build_opener( - urllib.request.HTTPCookieProcessor(cj), - urllib.request.HTTPSHandler()) + self.opener = urllib2.build_opener( + urllib2.HTTPCookieProcessor(cj), + urllib2.HTTPSHandler()) self._loginV2(username, password) self.id = self.getMe()['homes'][0]['id'] From 98bfc0164970ba1cf58ba3c45a1785340dc54383 Mon Sep 17 00:00:00 2001 From: Roel Baardman Date: Thu, 1 Feb 2018 09:25:09 +0100 Subject: [PATCH 2/2] Remove commented imports --- PyTado/interface.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/PyTado/interface.py b/PyTado/interface.py index ce16328..6776792 100755 --- a/PyTado/interface.py +++ b/PyTado/interface.py @@ -5,9 +5,6 @@ import logging import json import datetime -#import urllib.request -#import urllib.parse -#import urllib.error import urllib2 import urllib