我有此代码
import requests
import json
url = 'https://www.protocols.io/api/v3/protocols?filter=%20public%20&order_field=relevance&key=%20gel%22electrophoresis%20'
r = requests.get(url)
jason = r.json()
print (jason)
这可以在Spyder(3.7)中运行,并在Windows cmd中运行,但在Atom或git bash中则不能。我收到错误:
Traceback (most recent call last):
File "C:\Users\James\Documents\ProtocolScaper\test_3.py", line 13, in <module>
print(jason)
File "C:\Users\James\AppData\Local\Programs\Python\Python38-32\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 5399-5400: character maps to <undefined>
对于我的应用程序,我真的需要它在Atom中运行有任何想法吗?
这似乎是cp1252编码的Windows特定问题。由[]固定
jason.encode('cp1252, 'replace').decode('cp1252')