API call is working in postman but when i am using generated code, it is not working
Generated code:
import requests
url = "http://services.XXX.com/rest/v2/verification"
payload = "{\r\n \"startDate\": \"2000-12-25\",\r\n \"endDate\": \"2000-12-31\",\r\n \"format\": \"CSV\"\r\n}"
headers = {
'authorization': "Bearer XXXXX",
'content-type': "application/json",
'cache-control': "no-cache",
'postman-token': "XXX"
}
response = requests.request("POST", url, data=payload, headers=headers)
print(response.text)
I have tried to execute after removing postman-token also but still getting below error:
{"message":"Internal Server Error: correlationId=V2-ee8fb1b098490b8665dd936e8472978b","type":"error","code":1}
When using passing json data in requests
, you can pass a dictionary instead of string.
You can try this:
import requests
import json
url = "http://services.XXX.com/rest/v2/verification"
payload = "{\r\n \"startDate\": \"2000-12-25\",\r\n \"endDate\": \"2000-12-31\",\r\n \"format\": \"CSV\"\r\n}"
headers = {
'authorization': "Bearer XXXXX",
'content-type': "application/json",
'cache-control': "no-cache",
'postman-token': "XXX"
}
response = requests.post(url,json=json.loads(payload),headers=headers)
print(response.text)
You can change the payload variable, to a Json oblect this way:
Instead of:
payload = "{\r\n \"startDate\": \"2000-12-25\",\r\n \"endDate\": \"2000-12-31\",\r\n \"format\": \"CSV\"\r\n}"
You can use:
payload = {"startDate": "2000-12-25", "endDate": "2000-12-31", "format":"CSV"}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.