CURL-F到python请求发布



我阅读了Paypal API文档:

curl -v -X POST https://api.sandbox.paypal.com/v1/customer/disputes/PP-D-27803/provide-evidence 
-H "Content-Type: multipart/related; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW" 
-H "Authorization: Bearer Access-Token" 
-F 'input={
"evidences": [
{
"evidence_type": "PROOF_OF_FULFILLMENT",
"evidence_info": {
"tracking_info": [
{
"carrier_name": "FEDEX",
"tracking_number": "122533485"
}
]
},
"notes": "Test"
}
]
};type=application/json' 
-F 'file1=@NewDoc.pdf'

我不知道如何隐藏-F的输入:到python请求发布代码。它总是报告错误:

{u'name': u'VALIDATION_ERROR', u'links': [], u'details': [{u'issue': u'MISSING_OR_INVALID_REQUEST_BODY', u'location': u'body'}], u'message': u'Invalid request - see details', u'information_link': u'https://developer.paypal.com/docs/api/customer-disputes/#errors', u'debug_id': u'd9fa3425a02fe'}

有一个很酷的网站可以做这件事(因为你为它提供了curl命令(https://curl.trillworks.com/

输出

import requests
headers = {
'Content-Type': 'multipart/related; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW',
'Authorization': 'Bearer Access-Token',
}
files = {
'input': (None, '{n  "evidences": [n{n  "evidence_type": "PROOF_OF_FULFILLMENT",n  "evidence_info": {n  "tracking_info": [n    {n    "carrier_name": "FEDEX",n    "tracking_number": "122533485"n    }n  ]n  },n  "notes": "Test"n}n  ]n};type'),
'file1': ('NewDoc.pdf', open('NewDoc.pdf', 'rb')),
}
response = requests.post('https://api.sandbox.paypal.com/v1/customer/disputes/PP-D-27803/provide-evidence', headers=headers, files=files)

这应该让你知道它是如何完成的

最新更新