我试图向api做一个curl请求,但中文字符发出错误
UnicodeEncodeError: 'ascii' codec can't encode characters in position 96-97: ordinal not in range(128)
与php不同,我可以简单地将角色抛入curl,但python似乎有所不同。知道我怎么能这样做吗?
以下是我使用的代码:
query = urllib.parse.urlencode({'': '不存'})
url = 'https://www.googleapis.com/language/translate/v2' + query
print(url);
search_response = urllib.request.urlopen(url)
search_results = search_response.read().decode("utf8")
results = json.loads(search_results)
data = results['responseData']
print(data);