Skip to content
Snippets Groups Projects
Commit abf2870b authored by Adar Nimrod's avatar Adar Nimrod Committed by nimrod
Browse files

Decode responses.

Responses from urlopen are bytes. Decode them using the default locale
encoding. Supported since Python 2.3.
parent 9a5295e7
Branches
No related tags found
No related merge requests found
...@@ -92,7 +92,7 @@ def read_api_uri(uri, config, page=1): ...@@ -92,7 +92,7 @@ def read_api_uri(uri, config, page=1):
print("Trying URI {} with headers {}".format(uri, headers)) print("Trying URI {} with headers {}".format(uri, headers))
req = Request(uri, headers=headers) req = Request(uri, headers=headers)
return urlopen(req).read() return urlopen(req).read().decode()
def get_json(uri, config, obj_type=AttributeDict, page=1): def get_json(uri, config, obj_type=AttributeDict, page=1):
return json.loads(read_api_uri(uri, config, page), object_hook=obj_type) return json.loads(read_api_uri(uri, config, page), object_hook=obj_type)
...@@ -283,7 +283,7 @@ class JsonRepo(object): ...@@ -283,7 +283,7 @@ class JsonRepo(object):
print("Downloading %s" % target) print("Downloading %s" % target)
data = read_api_uri(url, self.config) data = read_api_uri(url, self.config)
with open(target, 'wb') as dl_file: with open(target, 'wb') as dl_file:
dl_file.write(data) dl_file.write(data.encode())
class IssuesRepo(JsonRepo): class IssuesRepo(JsonRepo):
def __init__(self, gh_repo, config): def __init__(self, gh_repo, config):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment