python-3.x - 无法连接到 HTTPS URL,因为 SSL 模块不可用
问题描述
当我使用 requets 模块获取 url 的文本时,出现错误:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/requests-2.18.1-py3.5.egg/requests/adapters.py", line 440, in send
timeout=timeout
File "/usr/local/lib/python3.6/site-packages/urllib3-1.21.1-py3.5.egg/urllib3/connectionpool.py", line 588, in urlopen
conn = self._get_conn(timeout=pool_timeout)
File "/usr/local/lib/python3.6/site-packages/urllib3-1.21.1-py3.5.egg/urllib3/connectionpool.py", line 250, in _get_conn
return conn or self._new_conn()
File "/usr/local/lib/python3.6/site-packages/urllib3-1.21.1-py3.5.egg/urllib3/connectionpool.py", line 821, in _new_conn
raise SSLError("Can't connect to HTTPS URL because the SSL "
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 "excuteUpdate.py", line 123, in <module>
downloadList = getapkList(list)
File "excuteUpdate.py", line 35, in getapkList
text = requests.get(detail_path).text
File "/usr/local/lib/python3.6/site-packages/requests-2.18.1-py3.5.egg/requests/api.py", line 72, in get
return request('get', url, params=params, **kwargs)
File "/usr/local/lib/python3.6/site-packages/requests-2.18.1-py3.5.egg/requests/api.py", line 58, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/local/lib/python3.6/site-packages/requests-2.18.1-py3.5.egg/requests/sessions.py", line 502, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python3.6/site-packages/requests-2.18.1-py3.5.egg/requests/sessions.py", line 612, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python3.6/site-packages/requests-2.18.1-py3.5.egg/requests/adapters.py", line 514, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: Can't connect to HTTPS URL because the SSL module is not available.
我已经安装了 ssl-1.0.2,并使用了命令
./configure --with-ssl=/usr/local/ssl
make
make install
但它没有用;
这是为了获取要解析的 url 文本。
代码是这样的:
text = requests.get(detail_path).text
解决方案
此错误的另一个可能原因(详见此 Stack Overflow 帖子)是您有一个名为ssl.py的自己的文件,您的脚本将导入此文件并导致出现相同的错误消息。
推荐阅读
- python - Python 2 中 abc.Sequence 的等价物
- linux - 我可以将 DLL 项目编译为 ARM 的共享对象 (.so) 文件吗?
- amqp - amqp_consume_message 如何表示意外帧
- python - 没有注册 OpKernel 以支持具有这些属性的 Op 'QuantizedReluX'
- python - 没有名为“django”的模块(没有 Virtualenv)
- python - 使用 sklearn pairwise_distances 计算 X 和 y 之间的距离相关性
- powershell - PowerShell 将数据从 CSV 导入和排序到 Automate New-CMBoundary (SCCM)
- settings - 查询输出“缩短” - 数据输出受限
- php - 如何获取PHP中特定字符之间的动态字符串值
- c# - 数据库功能