Python的请求库bundles the chardet
and urllib3
packages。
这可能意味着捆绑版本会有错误。我想知道是否有一个干净或简单的方法来获取请求使用不同版本的urllib3。例如,我可以pip install requests urllib3
然后请求自动使用该版本吗?
我知道请求automatically uses certifi
而不是其捆绑的证书,如果安装了certifi
,但我找不到urllib3
这样的文档。
否则我看到的选项是:
答案 0 :(得分:3)
截至今天,您所概述的选项是正确的。
有一些关于使用urllib3的系统版本的请求设置的讨论,但我不相信它已经实现。一些Linux发行版的打包实际上修补了使用urllib3的系统版本的请求(并相应地固定它),所以这不是一个不常见的请求。
至于使用带有urllib3的certifi,文档的it's outlined in the Security section。这是主要部分:
import urllib3
import certifi
http = urllib3.PoolManager(
cert_reqs='CERT_REQUIRED', # Force certificate check.
ca_certs=certifi.where(), # Path to the Certifi bundle.
)
# You're ready to make verified HTTPS requests.
try:
r = http.request('GET', 'https://example.com/')
except urllib3.exceptions.SSLError as e:
# Handle incorrect certificate error.
...