请求使这相当容易:
import requests
r = requests.get('https://ca-test.adyen.com/reports/download/MerchantAccount/[YourMerchantAccount]/[ReportFileName]', auth=('[YourReportUser]@Company.[YourCompanyAccount]', '[YourReportUserPassword]'), verify=False)
r.raise_for_status() #fail here if we got something other than 200
#for binary payloads:
with f as open('my file.bin', 'wb'):
f.write(r.content)
#or for text:
with f as open('my file.txt', 'wt'):
f.write(r.text)
这假设您的端点正在使用基本身份验证。如果是 Digest Auth,则更改为:
r = requests.get('https://ca-test.adyen.com/reports/download/MerchantAccount/[YourMerchantAccount]/[ReportFileName]', auth=requests.HTTPDigestAuth('[YourReportUser]@Company.[YourCompanyAccount]', '[YourReportUserPassword]'), verify=False)
注意verify=False
参数告诉请求不要检查 TLS 证书。您还可以设置verify=/path/to/certfile
是否有需要用于验证的证书。有关详细信息,请参阅https://requests.readthedocs.io/en/master/user/advanced/#ssl-cert-verification。
请求文档非常好:https ://requests.readthedocs.io/en/master/