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)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章