1👍
✅
You’ll need to decode the response before passing it to the json
module:
response = urllib.request.urlopen(search_url)
codec = response.info().get_param('charset', 'utf8') # default JSON encoding
json.loads(response.read().decode(codec))
The server is meant to provide you with a charset=...
parameter in theContent-Type
header, which the message.get_param()
method above would retrieve for you. If the parameter is absent, the code falls back to UTF-8, the default encoding for JSON as per the RFC.
Source:stackexchange.com