【问题标题】:Can't connect to HTTPS URL because the SSL module is not available无法连接到 HTTPS URL,因为 SSL 模块不可用
【发布时间】:2019-08-26 03:52:46
【问题描述】:

当我使用 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

【问题讨论】:

标签: python-3.x ssl suse


【解决方案1】:

我已经解决了这个问题: 首先,我重新安装 openssl-1.0.2,然后使用

mv /usr/bin/openssl /usr/bin/openssl.bak

mv /usr/include/bin/openssl /usr/include/bin/openssl.bak

要删除旧的ssl的软链接,然后

ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/ssl/include/bin/openssl /usr/include/bin/openssl

最后,重新制作并安装python源代码,建立软链接,这个问题就解决了。

【讨论】:

    【解决方案2】:

    此错误的另一个可能原因(如this Stack Overflow post 中所述)是您有一个名为 ssl.py 的自己的文件,您的脚本将导入此文件并导致相同的错误消息出现。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-03-05
      • 1970-01-01
      • 2020-08-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-10
      • 2019-06-05
      相关资源
      最近更新 更多