Search code examples
pythonpython-3.xcx-freeze

SSL exception while converting to *.exe with cx_freeze


After converting of my program to EXE with cx_freeze I get the following error:

   Traceback (most recent call last):
  File "C:\Users\tyszkap\AppData\Local\Continuum\Anaconda3\lib\site-packages\requests\packages\urllib3\util\ssl_.py", line 292, in s
sl_wrap_socket
    context.load_verify_locations(ca_certs, ca_cert_dir)
FileNotFoundError: [Errno 2] No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\tyszkap\AppData\Local\Continuum\Anaconda3\lib\site-packages\requests\adapters.py", line 376, in send
    timeout=timeout
  File "C:\Users\tyszkap\AppData\Local\Continuum\Anaconda3\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 559,
 in urlopen
    body=body, headers=headers)
  File "C:\Users\tyszkap\AppData\Local\Continuum\Anaconda3\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 345,
 in _make_request
    self._validate_conn(conn)
  File "C:\Users\tyszkap\AppData\Local\Continuum\Anaconda3\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 784,
 in _validate_conn
    conn.connect()
  File "C:\Users\tyszkap\AppData\Local\Continuum\Anaconda3\lib\site-packages\requests\packages\urllib3\connection.py", line 252, in
connect
    ssl_version=resolved_ssl_version)
  File "C:\Users\tyszkap\AppData\Local\Continuum\Anaconda3\lib\site-packages\requests\packages\urllib3\util\ssl_.py", line 294, in s
sl_wrap_socket
    raise SSLError(e)
requests.packages.urllib3.exceptions.SSLError: [Errno 2] No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\tyszkap\AppData\Local\Continuum\Anaconda3\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27, in <module>

    exec(code, m.__dict__)
  File "genderator.py", line 109, in <module>
  File "genderator.py", line 62, in checkLimits
  File "C:\Users\tyszkap\AppData\Local\Continuum\Anaconda3\lib\site-packages\genderize\__init__.py", line 88, in get
    params=params)
  File "C:\Users\tyszkap\AppData\Local\Continuum\Anaconda3\lib\site-packages\requests\sessions.py", line 480, in get
    return self.request('GET', url, **kwargs)
  File "C:\Users\tyszkap\AppData\Local\Continuum\Anaconda3\lib\site-packages\requests\sessions.py", line 468, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Users\tyszkap\AppData\Local\Continuum\Anaconda3\lib\site-packages\requests\sessions.py", line 576, in send
    r = adapter.send(request, **kwargs)
  File "C:\Users\tyszkap\AppData\Local\Continuum\Anaconda3\lib\site-packages\requests\adapters.py", line 447, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: [Errno 2] No such file or directory

Even though I don't use requests library explicitely I assume that Genderize does. So I have read a couple of posts about it and tried to pass the path to my cacert.pem file but it still doesn't solve my issue. This is how I formatted my setup.py file:

from cx_Freeze import setup, Executable
import requests.certs
import sys

executable = Executable( script = "genderator.py" )

# Add certificate to the build
options = {
    "build_exe": {
        'include_files' : [(requests.certs.where(), 'cacert.pem')]
    }
}

setup(
    version = "0",
    requires = ["requests"],
    options = options,
    executables = [executable])

I use Python 3.4.4 on Windows 7 64bit. Any idea what I am doing wrong?


Solution

  • You can try adding your certificate as an environment variable as described here and here.

    os.environ["REQUESTS_CA_BUNDLE"] = os.path("/path/to/cacert.pem")
    

    But what you've tried should work too.