python - 轻松升级 Requests 的 urllib3 版本?

标签 python python-requests urllib3

Python 的请求库 bundles the chardet and urllib3 packages .

这可能意味着捆绑版本会有错误。我想知道是否有一种干净或简单的方法来让请求使用不同版本的 urllib3。例如,我可以 pip install requests urllib3 然后让请求自动使用该版本吗?

我知道请求 automatically uses certifi如果安装了 certifi,而不是它的捆绑证书,但我找不到这样的 urllib3 文档。

否则我看到的选项是:

  1. 获取合并最新版本 urllib3 的请求,
  2. 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/

相关文章:

python - 如何告诉程序每天在准确的时间做某事?

python - 关闭来自另一个线程的 "Python Requests"连接

python - 使用 requests.get() 时缺少 Cookie 的某些部分?

python-2.7 - 如何禁用 urllib3 重试警告消息?

python - Tweepy OpenSSL.SSL.WantReadError

python - requests 无法从某些网站检索 html 内容

python - 自动连接到 lxc 容器并在容器内执行命令

python - 防止docker-compose在使用构建镜像时重新安装requirements.txt

python - 可以使用 cURL 访问 JIRA API,但不能使用 Requests

python - 将 2 个字节从字节数组转换为一个整数