Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Requests.exceptions.SSLError: Errno 185090050

Tags:

python

ssl

py2exe

Im trying to make a .py in .exe. In .py the application works fine but after I build it in .exe using py2exe I get this error:

Traceback (most recent call last):
File "filename.py", line 210, in <module>
File "requests\api.pyc", line 55, in get
File "requests\api.pyc", line 44, in requests
File "requests\sessions.pyc", line 461, in request
File "requests\sessions.pyc", line 567, in send
File "requests\adapters.pyc", line 399, in send
requests.exceptions.SLLError: [Errno 185090050] _ssl.c:344: error: 0B084002:x509 certificate routines: X509_load_cert_crl_file:system lib

And the line 210 in file is this

r2 = requests.get('https://www.hitbox.tv/api/chat/servers', timeout=timeoutDefault)

The setup.py is this:

from distutils.core import setup
import py2exe

setup(console=['filename.py'])

How I can solve this problem?

like image 431
Cosmin Avatar asked Jul 26 '14 16:07

Cosmin


2 Answers

The requests module (or actually urllib3 below it) fails to open the CA certificates file.

If you don't want to verify the server's certificate, you can change the call to:

r2 = requests.get('https://www.hitbox.tv/api/chat/servers', 
                  timeout=timeoutDefault, verify=False)

If you care about certificates (and you should), make sure that CA certs file is bundled with your application. According to the requests documentation:

You can also pass verify the path to a CA_BUNDLE file for private certs. You can also set the REQUESTS_CA_BUNDLE environment variable.

Requests can also ignore verifying the SSL certificate if you set verify to False.

See here: http://docs.python-requests.org/en/latest/user/advanced/#ssl-cert-verification

like image 199
Code Painters Avatar answered Oct 15 '22 17:10

Code Painters


I worked around this by monkey-patching requests to pass cacert.pem:

def _monkey_patch_requests():
    orig_send = HTTPAdapter.send
    def _send_no_verify(self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None):
        return orig_send(self, request, stream, timeout, 'cacert.pem' if verify else False, cert, proxies)
    HTTPAdapter.send = _send_no_verify

_monkey_patch_requests()

and copying <Python>/Lib/site-packages/certifi/cacert.pem to dist.

like image 30
ebsddd Avatar answered Oct 15 '22 15:10

ebsddd