1

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

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

verify=False也被使用,但这与问题无关,因为这是-kcurl 中的开关的类似物,它禁用验证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,请推荐另一个库。

4

1 回答 1

1

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/

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

于 2021-04-20T20:22:35.330 回答