python requests错误:(SSLError(“bad handshake: Error([(‘SSL routines’, ‘ssl3_get_record’, ‘wrong version number’)],)”,),)) 的解决办法

python requests 通过代理方式请求https网站时,出现错误:

(SSLError("bad handshake: Error([('SSL routines', 'ssl3_get_record', 'wrong version number')],)",),))

网上大部分解决办法都是无效的,不过还是找到了一篇靠谱的:https://blog.csdn.net/qq_37049050/article/details/76649005

也就是说https网站所用的SSL协议版本太低,而python解释器所用的SSL协议版本高于https网站所用的SSL协议版本,所以出现问题。

解决办法就是手动配置python,使requests选择更低版本的SSL协议。

首先在python脚本开头引入SSL适配器,如下:

from requests_toolbelt import SSLAdapter

然后加载低版本的SSL协议,如下:

self.session.mount(‘https://’, SSLAdapter(‘TLSv1’))


Posted

in

by

Tags:

Comments

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注