我想在通过内部公司链接向服务器发出请求期间忽略认证验证
。
使用 python requests
库我会这样做:
r = requests.get(link, allow_redirects=False,verify=False)
如何对 urllib2 库做同样的事情?
最佳答案
与此同时,urllib2 似乎默认验证服务器证书。 warning, that was shown in the past disappeared对于 2.7.9,我目前在具有自签名证书(和 Python 2.7.9)的测试环境中遇到了这个问题。
我的邪恶解决方法(不要在生产中这样做!):
import urllib2
import ssl
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
urllib2.urlopen("https://your-test-server.local", context=ctx)
According to docs直接调用 SSLContext 构造函数也应该有效。我没试过。
关于python忽略证书验证urllib2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19268548/