python - 将 Curl "-I --user"转换为 Python 请求

标签 python rest curl python-requests

我正在尝试将 cURL 命令转换为 python,但我正在努力

curl -I --user username:password https://an.api.on.the.internet/

我目前的尝试是:

import requests
cur = requests.get('https://an.api.on.the.internet', auth='username:password')

谁能帮我转换一下?谢谢

最佳答案

使用

requests.get(url, auth=(username, password))

参见 Basic Authentication 部分在 requests 文档中。

关于python - 将 Curl "-I --user"转换为 Python 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18363556/

相关文章:

javascript - 通过网页使用访问 token 检索 GitLab 工件文件并保存到磁盘

Swift:对 WordPress 的 REST 调用的身份验证

ruby-on-rails - Elasticsearch新手:与Rails和localhost:9200集成

python - 传递 kwarg 失败于 2.7

python - Groupby 并从组 : Pandas 的最小值中找出差异

python - 在python中搜索包含通配符的字符串

rest - Paypal REST API 付款 ID = IPN 交易 ID

PHP cURL 错误代码 60

c++ - Libcurl 不会发送 SMTP 退出命令

python - 如何定义带点的二维数组并分别限制 x 和 y