Big*_*myx 5 python ssl urllib2 ssl-certificate
我需要能够指定 SSL 证书 CA 根,但能够使用 Python 2.7.10urllib2库插入 HTTP cookie
ssl_handler = urllib2.HTTPSHandler()
opener = urllib2.build_opener(ssl_handler)
opener.addheaders.append(("Cookie","foo=blah"))
res = opener.open(https://example.com/some/info)
Run Code Online (Sandbox Code Playgroud)
我知道 urllib2 支持cafile参数,我应该在代码中的哪里使用它?
urllib2.urlopen(url[, 数据[, 超时[, cafile[, capath[, cadefault[, 上下文]]]]])
所以,请尝试:
urllib2.urlopen("https://example.com/some/info", cafile="test_cert.pem")
Run Code Online (Sandbox Code Playgroud)
或者
cxt = ssl.create_default_context(cafile="/path/test_cert.pem")
urllib2.urlopen("https://example.com/some/info", context=cxt)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10034 次 |
| 最近记录: |