首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用Python中的wget和curl选项下载文件?

如何使用Python中的wget和curl选项下载文件?
EN

Stack Overflow用户
提问于 2021-03-19 02:49:11
回答 1查看 135关注 0票数 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中的请求中?

非常感谢,

EN

回答 1

Stack Overflow用户

发布于 2021-03-19 03:14:36

Requests让这一切变得相当简单:

代码语言:javascript
运行
复制
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,则更改为:

代码语言:javascript
运行
复制
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/

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66697320

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档