python 请求中的哪里是 curl --proxy-insecure 类似物?

问题描述

在python中如何使用requests包通过禁用证书验证的代理发出https请求(类似于curl中的--proxy-insecure键)?我的代码

import requests
requests.get('https://ip.quotaguard.com',proxies={'https': 'login:password@eu-west-shield-01.quotaguard.com:9294'},verify=False)

verify=False 也被使用,但这与问题无关,因为它类似于 curl 中的 -k 开关,它禁用 ip.quotaguard.com 和代理上的验证eu-west-shield-01.quotaguard.com:9294 没有。

代码抛出错误 ValueError: check_hostname needs a SSL context with either CERT_OPTIONAL or CERT_required

通过curl,请求成功返回结果,这里是请求本身:

curl -x "https://login:password@eu-west-shield-01.quotaguard.com:9294" -L "https://ip.quotaguard.com" --proxy-insecure -k

如果有这种可能性,但在 requests 中没有,请推荐另一个图书馆。

解决方法

Vladimir,我看到您正在使用 QuotaGuard 来解决这个问题。我很抱歉延迟捕捉这个问题来为您提供答案。我们只是在加强对 SO 的支持,再次为延迟道歉。

对于您的问题,以下链接中的第一句话适用:Requests 是一个很棒的 Python HTTP 库。它允许您基于每个请求指定经过身份验证的代理,以便您可以选择何时通过静态 IP 进行路由。

https://devcenter.heroku.com/articles/quotaguardshield#https-proxy-python-django

requests 库仅使用 HTTP 代理,而不使用 HTTPS 代理。因此,在选项中列出 HTTPS 时,您对 HTTPS 请求使用 HTTP 代理,而不是对 HTTP(S) 请求使用 HTTPS 代理。因此,在您的情况下,QuotaGuard Static 会起作用,而不是 QuotaGuard Shield。 (您的连接字符串看起来像是在使用 Shield)

检查 QuotaGuard Static 和 QuotaGuard Shield 之间的区别可能会有所帮助,因为它解释了为什么会这样:

https://www.quotaguard.com/why-is-quotaguard-shield-more-secure-than-quotaguard-static/

希望对您有所帮助,如果您在设置方面需要更多帮助,请在此处告诉我或通过 Support 与我们联系。