代码如下
import requests
b_dict = {"a":1}
result = requests.patch(url="XXX", data=b_dict, headers={'content-type': 'application/json',"accept": "application/json'"})
print(result.text)
报错:
{“detail”:[{“loc”:[“body”,0],“msg”:“Expecting value: line 1 column 1 (char 0)”,“type”:“value_error.jsondecode”,“ctx”:{“msg”:“Expecting value”,“doc”:“test_other=Test_Case_1&test_camera=Test_Case_2&test_camera=Test_Case_1”,“pos”:0,“lineno”:1,“colno”:1}}]}
解决办法:
因为接口中需要接收的参数是json格式,故需要将字典转为json
将b_dict转为json格式,如下:
import requests
import json
b_dict = {"a":1}
result = requests.patch(url="XXX", data=json.dumps(b_dict), headers={'content-type': 'application/json',"accept": "application/json'"})
print(result.text)