我想让你用这个Adyen请求
$ wget --http-user='[YourReportUser]@Company.[YourCompanyAccount]' --http-password='[YourReportUserPassword]' --quiet --no-check-certificate https://ca-test.adyen.com/reports/download/MerchantAccount/[YourMerchantAccount]/[ReportFileName]
在Python中下载文件。如何将wget的选项放入urllib2或requests中的请求中?
非常感谢,
发布于 2021-03-19 03:14:36
Requests让这一切变得相当简单:
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。
Requests文档非常棒:https://requests.readthedocs.io/en/master/
https://stackoverflow.com/questions/66697320
复制相似问题