Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python wsgi:ssl-error Can't connect to HTTPS URL because the SSL module is not available

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.

Droplet: Ubuntu 16.04 Python version: 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

[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.

Any help in a good direction would be appreciated. Thanks

like image 445
softvar Avatar asked Jan 28 '17 10:01

softvar


1 Answers

If you installed Python from the source you'll have to rerun

./configure
make
sudo checkinstall

AFTER you have installed openssl (I'm assuming through sudo apt install openssl).

like image 53
Kent Shikama Avatar answered Sep 28 '22 00:09

Kent Shikama