req = requests.post调用
req.statu_scode == 200,但是仍然报错:
{"code":"404","message":"参数解析异常,请检查方法的参数是否有效"}
通过postman调用ok,代码直接执行也ok:
修改为json格式调用,报错:
data_pay =[{
'userId': '867857567567568678',
'orderCode': '999010188371',
'paymentType': '1',
'paymentMethod': 'ICBC_SBERBANK'
}]
PS E:\Python> & C:/Users/AppData/Local/Programs/Python/Python38/python.exe e:/Python/Test/OrderGui/OrderStatus.py
200
{"info":"Duplicate data","resultCode":2000}
一开始以为'ContentType': 'application/json'格式不对应导致,添加后:
resp_web = requests.post(pay_url,data=payload,headers=headers) 还是报错。
最后排查原因为json格式错误导致,键值对使用了单引号。这里贴一下json的基础知识:
修改后,调用ok。
pay_url = 'https://rpcos.test.hihonor.com/invoke/com.huawei.vmall.oms.dubbo.api.OMSInterfaceForBalanceKey.updatePaymentStatus'
headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36',
'ContentType': 'application/json'
}
data_pay =[{
"userId": "867857567567568678",
"orderCode": "999010188371",
"paymentFee": "0",
"paymentAmount": "1000",
"paymentNo": "99910188375",
"paymentTime": "2021-10-18 11:22:00 +0800",
"paymentStatus": "1",
"paymentType": "1",
"paymentMethod": "ICBC_SBERBANK"
}]
payload="[{\r\n\t\"userId\": \"867857567567568678\",\r\n\t\"orderCode\": \"999010188371\", \r\n\t\"paymentFee\": \"0\",\r\n\t\"paymentAmount\": \"7300\",\r\n\t\"paymentNo\": \"48010188375\",\r\n\t\"paymentTime\": \"2021-10-20 11:22:00 +0800\",\r\n\t\"paymentStatus\": \"1\",\r\n\t\"paymentType\": \"1\",\r\n\t\"paymentMethod\": \"ICBC_SBERBANK\"\r\n}]"
resp_web = requests.post(pay_url,json=data_pay,headers=headers)
resp_web1 = requests.post(pay_url,data=payload,headers=headers)
print(resp_web.status_code)
print(resp_web.text)
print(resp_web1.status_code)
print(resp_web1.text)