BELOW是我在Python中的代码,我不确定该怎么做才能使它起作用,我尝试探索Internet上的每一个选项和每条文章,还使用Postman生成代码并修改了代码,但并不成功 -
import requests
import json
url = "http://localhost:8080/apim/execute/repayments/v3/dummy-acceptance"
payload = {
"customer": {
"id": "cust00001",
"name": {
"first_name": "Matthew",
"last_name": "Peterson"
},
"email": "[email protected]"
},
"method": {
"type": "FPS"
},
"transaction": {
"id": "dummy456721094299",
"amount": 62.08,
"currency_code": "GBP",
"country_code": "GB",
"url": {
"accepted": "http://accepted.com",
"declined": "http://declined.com"
},
"reason": "Purchased goods",
"reference": "ref_0974299",
"product_info": [
{
"id": "prod00007",
"name": "Apple Laptop",
"quantity": 1,
"amount": 62.08,
"description": "Laptop Purchased"
}
],
"expiry_time": 1000
}
}
headers = {
"Idempotency-Id": "12456478591",
"Content-Type": "application/json",
"Merchant-Id": "dummyuEFPS2409",
"Authorization": "Bearer eyJ0eXAiOiJKV1QMFB231pUMg1jHfU2SaDfRj2b_QJoPydIzXfsPlmSEGMzjRUDI",
"Operation": "AUTHORIZE"
}
try:
response = requests.post(url, headers=headers, data=json.dumps(payload))
response.raise_for_status() # Raise an exception for HTTP errors
print("success", response.json())
except requests.exceptions.HTTPError as errh:
print("HTTP error occurred:", errh)
print("Response content:", response.text)
except requests.exceptions.ConnectionError as errc:
print("Error Connecting:", errc)
except requests.exceptions.Timeout as errt:
print("Timeout Error:", errt)
except requests.exceptions.RequestException as err:
print("An error occurred:", err)
Content-Length
标头。
要研究的目标区域包括:划分如何发送有效负载(例如,使用JSON =参数而不是data = json.dumps(有效载荷))。
邮递员可能会自动添加的任何额外或缺少的标头。
一种测试方法是使用Postman Codegen从Inside Postman生成代码,并查看是否有效。