使用postman(Python Requests)生成的代码并将其插入到python脚本中

时间:2015-08-11 16:31:56

标签: python http python-requests postman

我知道API调用在Postman中有效,但是当我尝试使用Postman为Python请求代码生成的代码时,它不起作用。我很确定问题是在有效负载格式化,但我看不到它。任何帮助将不胜感激。

import requests

url = "https://api.logmycalls.com/services/uploadCall"

payload = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"api_key\"\r\n\r\n***SecretAPIKey***\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"api_secret\"\r\n\r\n***SecretKey***\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"ouid\"\r\n\r\n48544\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"audio\"; filename=\"Ch6WA1WgGTpI4GbI.wav\"\r\nContent-Type: audio/x-wav\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"calldate\"\r\n\r\n2015-07-01 12:00:00\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"caller_id\"\r\n\r\n8888888888\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"ringto_number\"\r\n\r\n8888888888\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"mine_call\"\r\n\r\n1\r\n-----011000010111000001101001--"

headers = {'content-type': 'multipart/form-data; boundary=---011000010111000001101001'}

response = requests.request("POST", url, data=payload, headers=headers)

print(response.text)

0 个答案:

没有答案