Steamの在庫からJSONを取得しようとしています。JSONのURLからのエンコーディングとダウンロード
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")
これで、エンコードに問題が発生しました。
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
...すべてのヘルプ:スチームは、クラッシュにJSONの一部の原因となる「ブラックスター」(「\のu2605」)のような記号を使用しています...役に立つだろう。
ようこそ、地獄に! [link](http://www.joelonsoftware.com/articles/Unicode.html) – saq7
.decode( 'utf-8')を削除するとどうなりますか? – glls
すでに試みた: ファイル "C:\ Python34 \ libに\ JSON \ __ init__.py"、行312、負荷の の.__クラス__.__ name__)) はTypeError:JSONオブジェクトはstrをしなければならない、ではない 'バイト' –