【问题标题】:Python requests equivalent for cURL's --location-trustedPython 请求等效于 cURL 的 --location-trusted
【发布时间】:2015-12-18 16:03:48
【问题描述】:

使用 cURL,我可以执行 --location-trusted 以允许将名称+密码发送到站点可能重定向到的所有主机 (http://curl.haxx.se/docs/manpage.html#--location-trusted)。

我可以在 Python 中使用 requests 库做类似的事情吗?

【问题讨论】:

    标签: python curl python-requests http-authentication


    【解决方案1】:

    requests 会自动处理重定向: (http://docs.python-requests.org/en/latest/user/quickstart/#redirection-and-history)
    所以,这应该是一个很好的起点(如果你还没有经历过): (http://docs.python-requests.org/en/latest/user/authentication/)

    【讨论】:

    • 但是当重定向发生时,用户名和密码对不会被传递。所以,我在重定向时遇到了身份验证问题。
    • @jianweichuah 你找到解决办法了吗?
    【解决方案2】:

    如果您必须使用 libcurl(您可以合法使用!),您需要将 CURLOPT_UNRESTRICTED_AUTH 选项传递给它。

    虽然文档页面本身没有提到它,但这是 libcurl 等效的命令行--location-trusted 标志。请参阅the CVE page,他们在其中介绍了--location-trusted,了解更多信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-25
      相关资源
      最近更新 更多