【问题标题】:Python wsgi:ssl-error Can't connect to HTTPS URL because the SSL module is not availablePython wsgi:ssl-error 无法连接到 HTTPS URL,因为 SSL 模块不可用
【发布时间】:2017-01-28 10:50:29
【问题描述】:

我刚刚从 Amazon ec2 实例迁移到 DigitalOcean droplet。 一切似乎都运行良好,直到我在配置我的 python 应用程序、WSGI 和 apache2 时遇到 SSL 问题。

Droplet:Ubuntu 16.04 Python版本:2.7.12

虚拟主机文件

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>                                                                         


```

我的应用程序使用 python requests 模块发出 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.

我搜索了很多。 我试过安装openssl,其他conf,但真的很沮丧。 我不知道它在 Amazon ec2 中如何运行顺利,但在 Droplet 中却没有。

我们将不胜感激。谢谢

【问题讨论】:

  • 你是如何得到你现在使用的 python 版本的?您是否从 Ubuntu 的包管理器安装了二进制文件?
  • 我使用askubuntu.com/questions/101591/…安装python 2.7.10

标签: python ssl python-requests wsgi digital-ocean


【解决方案1】:

如果您从源代码安装 Python,则必须重新运行

./configure
make
sudo checkinstall

安装 openssl 后(我假设通过 sudo apt install openssl)。

【讨论】:

  • 我和你提到的一样。但它没有用。有什么原因,为什么?
  • 嗯不知道。不过很高兴您找到了解决方法。
  • 为了确保你有 openssl 和所有其他依赖项来编译 python3.6,我在我的 Ubuntu 16.04 上使用了这个:sudo apt-get install build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev
【解决方案2】:

我认为我安装的 python 版本有问题。要么安装了多个 python 版本,要么构建没有正确构建。我在Ubuntu 16.04 digitalOcean machine 上,它没有安装python。所以我不得不手动安装它。我按照https://askubuntu.com/questions/101591/how-do-i-install-python-2-7-2-on-ubuntu上给出的答案@

但是,似乎没有任何效果。

最后,我创建了一台全新的机器,但这次是Ubuntu 14.04,它已经安装了python。当我安装依赖项并部署我的 Flask 应用程序时,它可以正常工作。

将 Ubuntu 16.04(无 python)更改为 Ubuntu 14.04(安装了 python)。

【讨论】:

    【解决方案3】:

    我玩得很开心(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
    

    【讨论】:

      【解决方案4】:

      安装opensslopessl-devel后,无需再次配置python。

      运行以下命令:

      make 
      make install
      

      【讨论】:

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