当我第一次在Elementary OS上尝试使用Python Requests模块获取网页时,我遇到了SSLError。有一个简单的解决方案:
Python 3,尝试:
import requests
page = requests.get('https://api.github.com/events')
获取SSLError:
/usr/local/bin/python3 /home/led/PycharmProjects/urllib_p/urllib_p.py
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/requests/adapters.py", line 376, in send
timeout=timeout
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 549, in urlopen
conn = self._get_conn(timeout=pool_timeout)
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 251, in _get_conn
return conn or self._new_conn()
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 764, in _new_conn
raise SSLError("Can't connect to HTTPS URL because the SSL "
requests.packages.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 "/home/led/PycharmProjects/urllib_p/urllib_p.py", line 5, in <module>
page = requests.get('https://api.github.com/events')
File "/usr/lib/python3/dist-packages/requests/api.py", line 67, in get
return request('get', url, params=params, **kwargs)
File "/usr/lib/python3/dist-packages/requests/api.py", line 53, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 468, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 576, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python3/dist-packages/requests/adapters.py", line 447, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: Can't connect to HTTPS URL because the SSL module is not available.
verify = False没有意义(同样的错误)
答案 0 :(得分:0)
使用文本编辑器打开安装文件并搜索SSL。你会发现:
# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
#SSL=/usr/local/ssl
#_ssl _ssl.c \
# -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
# -L$(SSL)/lib -lssl -lcrypto
取消评论最后四行。
在终端:转到Python_directory,然后:
sudo ./configure
sudo make
sudo make install
答案 1 :(得分:0)
我用以下命令解决了这个问题:
sudo cp -f /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1 /usr/local/lib/
sudo cp -f /usr/lib/x86_64-linux-gnu/libssl.so.1.1 /usr/local/lib/
sudo ln -sfn /usr/lib/x86_64-linux-gnu/libcrypto.a /usr/local/lib/
sudo ln -sfn /usr/lib/x86_64-linux-gnu/libssl.a /usr/local/lib/
sudo ln -sfn /usr/lib/x86_64-linux-gnu/libssl.so.1.1 /usr/local/lib/