执笔墨飘烟2021/4/6urllib3.exceptions.SSLError处理方案
场景
刚配置的linux系统,安装完python3.7.9后使用requests模块,抛出异常:
Traceback (most recent call last):
File "/usr/local/python3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 659, in urlopen
conn = self._get_conn(timeout=pool_timeout)
File "/usr/local/python3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 279, in _get_conn
return conn or self._new_conn()
File "/usr/local/python3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 948, in _new_conn
"Can't connect to HTTPS URL because the SSL module is not available."
urllib3.exceptions.SSLError: Can't connect to HTTPS URL because the SSL module is not available.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/python3/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/usr/local/python3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 727, in urlopen
method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
File "/usr/local/python3/lib/python3.7/site-packages/urllib3/util/retry.py", line 446, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='ipservice.3g.163.com', port=443): Max retries exceeded with url: /ip (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available."))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test.py", line 6, in <module>
rep = requests.get(url, verify=False)
File "/usr/local/python3/lib/python3.7/site-packages/requests/api.py", line 76, in get
return request('get', url, params=params, **kwargs)
File "/usr/local/python3/lib/python3.7/site-packages/requests/api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/local/python3/lib/python3.7/site-packages/requests/sessions.py", line 530, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/python3/lib/python3.7/site-packages/requests/sessions.py", line 643, in send
r = adapter.send(request, **kwargs)
File "/usr/local/python3/lib/python3.7/site-packages/requests/adapters.py", line 514, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='ipservice.3g.163.com', port=443): Max retries exceeded with url: /ip (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available."))
尝试方案
- 更新spacy(地址:https://blog.csdn.net/zcyzhangzhou/article/details/86572845):失败
- 更新openssl(地址:http://www.45fan.com/article.php?aid=19073158040128417480594681):失败
- 安装requests的依赖包(地址:https://www.cnblogs.com/hum0ro/p/9536033.html):失败
解决方案
因为python安装的时候可能没有安装openssl相关的开发包,因此需要手动安装:yum install openssl-devel
安装好后重新编译一遍python或者删除重装
参考
https://docsxyz.com/wiki/python/ssl-module-is-not-available