首页 > 解决方案 > 为什么 Charmap 只以字典形式抛出错误,而不是 JSON 形式?

问题描述

response = requests.request("GET", requestUrl, headers=headers, data=payload)
data = response.json()
dataJSON = json.dumps(data)
print (dataJSON) #Prints perfectly fine
#dataDict = json.loads(dataJSON)
#print(dataDict) #throws charmap Exception that is below
File "C:\Program Files\Python38\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 107450-107451: character maps to <undefined>

我已经尝试过 UTF-8 编码,但这并不能解决这个问题。预先感谢您的帮助!

标签: pythonjsondictionaryencoding

解决方案


推荐阅读