python接口请求 JSON parse error: Unrecognized token ‘type‘: was expecting ‘null‘

python接口请求 JSON parse error: Unrecognized token ‘type‘: was expecting ‘null‘,第1张

python接口请求 JSON parse error: Unrecognized token ‘type’: was expecting ‘null’

报错的原因:
传参不正确,协议头信息的Content-Type字段定义了请求格式,传json数据请求头为:Content-Type:application/json

解决办法:
先查看参数的类型:print(type(data))
data1 = json.dumps(data)#类型转换
r = requests.post(url=url, headers=headers, data=data1)
res = requests.post(url=url, params=params, json=data, headers=headers)

原文链接:https://www.jianshu.com/p/33770ffbeba6

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/917542.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-16
下一篇 2022-05-16

发表评论

登录后才能评论

评论列表(0条)

保存