在Python请求中选择SSL版本

Over the last few months (and probably for quite a while before then too), a few issues have been raised on the Requests GitHub page asking how to select the version of SSL used by Requests. This is actually simple once you know how, so I thought I’d write a short post to show you how it’s done.

在过去的几个月中(可能还有很长一段时间), Requests GitHub页面上出现了一些问题,询问如何选择Requests使用的SSL版本。 一旦您知道如何做,这实际上很简单,所以我想写一篇简短的文章向您展示它是如何完成的。

A quick note before we begin: it is not possible to select the version of SSL you want to use before Requests v1.0.0 without changing the underlying library code. The following set of instructions will not work if you’re running an earlier version.

在开始之前的简短提示: 不更改基础库代码的情况下,无法在Requests v1.0.0之前选择要使用的SSL版本 。 如果您运行的是早期版本,则以下说明将不起作用。

怎么做的 (How It’s Done)

Altogether this is relatively simple. To change the SSL version used in HTTPS, you are expected to subclass the HTTPAdapter class and mount it to a Session object. If, for example, you wanted to force the use of TLSv1, your new Transport Adapter will look like this:

总体而言,这相对简单。 要更改HTTPS中使用的SSL版本,您应该将HTTPAdapter类子类化并将其安装到Session对象。 例如,如果您想强制使用TLSv1,则新的传输适配器将如下所示:

from from requests.adapters requests.adapters import import HTTPAdapter
HTTPAdapter
from from requests.packages.urllib3.poolmanager requests.packages.urllib3.poolmanager import import PoolManag
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值