Skip to content
Snippets Groups Projects
Commit 952c4c56 authored by Srdjan Grubor's avatar Srdjan Grubor
Browse files

Make sure to decode web responses with UTF-8

Without this, running this code on python2 fails with the following:
`UnicodeDecodeError: 'ascii' codec can't decode byte ... in position ...: ordinal not in range(128)`

Python3 is fine since it uses utf8 by default.
parent e375bbb2
No related branches found
No related tags found
No related merge requests found
...@@ -97,7 +97,7 @@ def read_api_uri(uri, config, page=1): ...@@ -97,7 +97,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().decode() return urlopen(req).read().decode('utf-8')
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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment