I'm trying to get JSON from a Steam inventory. I get the data like this :
def downloadString(url):
req = urllib.request.Request(
url,
data=None,
headers={
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 Safari/537.36'
}
)
f = urllib.request.urlopen(req)
return f.read().decode("utf-8")
Now, I get a problem with encoding. Steam is using symbols like "Black star" ('\u2605') which causes the json part to crash :
def test(string):
print(json.loads(string))
test(downloadString(url))
File "C:\Python34\lib\encodings\cp1252.py", line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_table)[0] UnicodeEncodeError: 'charmap' codec can't encode character '\u2605' in position 83559: character maps to
I don't really understand how I can do something else... Any help would be... helpful.
codec
module to deal with the UTF-8 data – Marcus Müller