Python 的请求库 bundles the chardet
and urllib3
packages .
这可能意味着捆绑版本会有错误。我想知道是否有一种干净或简单的方法来让请求使用不同版本的 urllib3。例如,我可以 pip install requests urllib3
然后让请求自动使用该版本吗?
我知道请求 automatically uses certifi
如果安装了 certifi
,而不是它的捆绑证书,但我找不到这样的 urllib3
文档。
否则我看到的选项是:
- 获取合并最新版本 urllib3 的请求,
- fork 我自己的请求版本并使用它。
最佳答案
截至今天,您列出的选项都是正确的。
有人说要有一个使用 urllib3 系统版本的请求设置,但我认为它没有实现。一些 Linux 发行版的打包实际上修补了使用系统版本的 urllib3 的请求(并相应地固定它),所以这不是一个不常见的请求。
关于将 certifi 与 urllib3 一起使用,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.
...
关于python - 轻松升级 Requests 的 urllib3 版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28157151/