【发布时间】:2019-07-14 00:33:50
【问题描述】:
使用 requests 库执行返回 JSON 响应的 http GET 当响应字符串包含 unicode char 时出现此错误:
json.decoder.JSONDecodeError: Invalid control character at: line 1 column 20 (char 19)
使用 Postman 执行相同的 http 请求,json 输出为:
{ "value": "VILLE D\u0019ANAUNIA" }
我的python代码是:
data = requests.get(uri, headers=HEADERS).text
json_data = json.loads(data)
我可以在使用 json.loads(...) 执行转换之前删除或替换所有 Unicode 字符吗?
【问题讨论】:
-
什么是原始响应内容 (
print(requests.get(uri, headers=HEADERS).content))?这可能是由编码问题引起的......
标签: python json python-3.x