2

我希望你使用这个 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 中的请求中?

非常感谢,

4

1 回答 1

3

请求使这相当容易:

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/

于 2021-03-18T19:14:36.210 回答