-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
13 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
""" Remotsy library for python | ||
Copyright 2018 Jorge Cisneros [email protected] | ||
""" | ||
from json import dumps, loads | ||
from urllib2 import Request, urlopen, HTTPError, URLError | ||
import sys | ||
from json import dumps, loads | ||
try: | ||
# For Python 3.0 and later | ||
from urllib.request import urlopen, Request, HTTPError, URLError | ||
except ImportError: | ||
# Fall back to Python 2's urllib2 | ||
from urllib2 import Request, urlopen, HTTPError, URLError | ||
|
||
|
||
class API(object): | ||
|
@@ -19,12 +24,12 @@ def post(self, url, data): | |
if self.auth_key is not None: | ||
data["auth_key"] = self.auth_key | ||
try: | ||
resp = urlopen(req, dumps(data)) | ||
resp = urlopen(req, dumps(data).encode("utf-8")) | ||
except HTTPError as errobj: | ||
print errobj | ||
print (errobj) | ||
sys.exit(-1) | ||
except URLError as errobj: | ||
print errobj | ||
print (errobj) | ||
sys.exit(-2) | ||
else: | ||
body = loads(resp.read()) | ||
|
@@ -81,4 +86,3 @@ def update_firmware(self, iddev): | |
""" Function to update Remotsy's firmware""" | ||
ret = self.post("devices/updatefirmware", {"id_dev": iddev}) | ||
return ret["status"] == "success" | ||
|