Python wsgi:ssl-error 无法连接到 HTTPS URL 因为 SSL 模块不可用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41908895/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python wsgi:ssl-error Can't connect to HTTPS URL because the SSL module is not available
提问by softvar
I just migrated from Amazon ec2 instance to DigitalOcean droplet. Everything seems to be working fine until I ran into the SSL problem when I configure my python app, WSGI and apache2.
我刚刚从 Amazon ec2 实例迁移到 DigitalOcean droplet。一切似乎都运行良好,直到我在配置 python 应用程序、WSGI 和 apache2 时遇到 SSL 问题。
Droplet: Ubuntu 16.04 Python version: 2.7.12
Droplet:Ubuntu 16.04 Python 版本:2.7.12
VirtualHost file
虚拟主机文件
WSGISocketPrefix /var/run/wsgi
<VirtualHost *:80>
ServerName c123456.com
#translatr.varunmalhotra.xyz
#DocumentRoot /var/www/html
#ErrorDocument 404 /notFound404.html
ErrorLog /var/log/translatr.error.log
CustomLog /var/log/translatr.access.log combined
WSGIDaemonProcess translatrapp python-path=/var/www/html/translatr:/var/www/html/translatr/ENV/lib/python2.7/site-packages
WSGIScriptAlias / /var/www/html/translatr/translatrapp.wsgi
<Directory /var/www/html/translatr>
WSGIProcessGroup translatrapp
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
```
``
My app uses python requests
module to make a GET request.
The requests return 500
and when I check my logs, I could see
我的应用程序使用 pythonrequests
模块发出 GET 请求。请求返回500
,当我检查日志时,我可以看到
[Sat Jan 28 10:46:23.754636 2017] [wsgi:error] [pid 6627:tid 139754554279680] request
= requests.get(link, headers=agents, verify=False)
[Sat Jan 28 10:46:23.754641 2017] [wsgi:error] [pid 6627:tid 139754554279680] File "/va
r/www/html/translatr/ENV/lib/python2.7/site-packages/requests/api.py", line 69, in get
[Sat Jan 28 10:46:23.754645 2017] [wsgi:error] [pid 6627:tid 139754554279680] return
request('get', url, params=params, **kwargs)
[Sat Jan 28 10:46:23.754650 2017] [wsgi:error] [pid 6627:tid 139754554279680] File "/va
r/www/html/translatr/ENV/lib/python2.7/site-packages/requests/api.py", line 50, in reques
t
[Sat Jan 28 10:46:23.754655 2017] [wsgi:error] [pid 6627:tid 139754554279680] respons
e = session.request(method=method, url=url, **kwargs)
[Sat Jan 28 10:46:23.754659 2017] [wsgi:error] [pid 6627:tid 139754554279680] File "/va
r/www/html/translatr/ENV/lib/python2.7/site-packages/requests/sessions.py", line 468, in
request
[Sat Jan 28 10:46:23.754664 2017] [wsgi:error] [pid 6627:tid 139754554279680] resp =
self.send(prep, **send_kwargs)
[Sat Jan 28 10:46:23.754669 2017] [wsgi:error] [pid 6627:tid 139754554279680] File "/va
r/www/html/translatr/ENV/lib/python2.7/site-packages/requests/sessions.py", line 597, in
send
[Sat Jan 28 10:46:23.754673 2017] [wsgi:error] [pid 6627:tid 139754554279680] history
= [resp for resp in gen] if allow_redirects else []
[Sat Jan 28 10:46:23.754678 2017] [wsgi:error] [pid 6627:tid 139754554279680] File "/va
r/www/html/translatr/ENV/lib/python2.7/site-packages/requests/sessions.py", line 195, in
resolve_redirects
[Sat Jan 28 10:46:23.754683 2017] [wsgi:error] [pid 6627:tid 139754554279680] **adapt
er_kwargs
[Sat Jan 28 10:46:23.754687 2017] [wsgi:error] [pid 6627:tid 139754554279680] File "/va
r/www/html/translatr/ENV/lib/python2.7/site-packages/requests/sessions.py", line 576, in
send
[Sat Jan 28 10:46:23.754692 2017] [wsgi:error] [pid 6627:tid 139754554279680] r = ada
pter.send(request, **kwargs)
[Sat Jan 28 10:46:23.754697 2017] [wsgi:error] [pid 6627:tid 139754554279680] File "/va
r/www/html/translatr/ENV/lib/python2.7/site-packages/requests/adapters.py", line 433, in
send
[Sat Jan 28 10:46:23.754702 2017] [wsgi:error] [pid 6627:tid 139754554279680] raise S
SLError(e, request=request) │
[Sat Jan 28 10:46:23.754706 2017] [wsgi:error] [pid 6627:tid 139754554279680] SSLError: C│
an't connect to HTTPS URL because the SSL module is not available.
I have searched a lot.
I have tried installing openssl
, other conf, but really frustrated.
I don't know how it's working smooth in Amazon ec2 but not in Droplet.
我已经搜索了很多。我试过安装openssl
其他 conf,但真的很沮丧。我不知道它在 Amazon ec2 中是如何顺利工作的,但在 Droplet 中却不是。
Any help in a good direction would be appreciated. Thanks
任何在一个好的方向上的帮助将不胜感激。谢谢
采纳答案by softvar
I think there was something wrong with my python version installed. Either there were multiple python versions installed or the build was not properly built. I was on Ubuntu 16.04 digitalOcean machine
which comes without python
installation. So I had to install it manually. I followed the answer given on https://askubuntu.com/questions/101591/how-do-i-install-python-2-7-2-on-ubuntu
我认为我安装的 python 版本有问题。要么安装了多个 python 版本,要么构建未正确构建。我是在Ubuntu 16.04 digitalOcean machine
没有python
安装的情况下。所以我不得不手动安装它。我按照https://askubuntu.com/questions/101591/how-do-i-install-python-2-7-2-on-ubuntu 上给出的答案进行操作
But, nothing seemed to work.
但是,似乎没有任何效果。
Finally, I created a fresh new machine but this time, it was Ubuntu 14.04
which comes with python
being already installed. When I installed the dependencies and deployed my Flask app, it worked properly.
最后,我创建了一个全新的机器,但这个时候,它是Ubuntu 14.04
附带python
被已安装。当我安装依赖项并部署我的 Flask 应用程序时,它运行正常。
Changed Ubuntu 16.04(without python) to Ubuntu 14.04(with python installed).
将 Ubuntu 16.04(没有 python)更改为 Ubuntu 14.04(安装了 python)。
回答by Kent Shikama
If you installed Python from the source you'll have to rerun
如果您从源代码安装 Python,则必须重新运行
./configure
make
sudo checkinstall
AFTER you have installed openssl (I'm assuming through sudo apt install openssl
).
在您安装了 openssl 之后(我假设通过sudo apt install openssl
)。
回答by Amichai Schreiber
I had a hell of a time (Ubuntu 14.04, Python 3.7), but managed to get it to work eventually:
我玩得很开心(Ubuntu 14.04,Python 3.7),但最终设法让它工作:
apt install libssl libssl-dev
# compile Python from source:
wget https://www.python.org/ftp/python/3.7.5/Python-3.7.5.tgz
tar -xf Python-3.7.5.tgz
./configure --with-openssl=/openssl/ # make sure that this is where x509_vfy.h sits
make && make altinstall
回答by NoorShaik Ali
After installing openssland opessl-devel, there is no need to configure python again.
安装openssl和opessl-devel 后,无需再次配置python。
Run the following commands:
运行以下命令:
make
make install