I am getting JSON from internet (Stackoverflow API) and trying to decode it:
import urllib.request
url = "https://api.stackexchange.com/2.2/questions?order=desc&sort=activity&site=stackoverflow"
fp = urllib.request.urlopen(url)
mybytes = fp.read()
mystr = mybytes.decode("utf8")
fp.close()
print(mystr)
I got the error:
Traceback (most recent call last): File "code.py", line 6, in mystr = mybytes.decode("utf8") UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8b in position 1: invalid start byte
Why and how can I fix it?