Python app using Requests has missing files and errors after cx_freeze

1.6k Views Asked by At

EDIT:

So I ended up just using Portable Python. My goal was to run a Python script on a Windows Server that doesn't have Python installed, and that's what PP can do. Not really a solution to my original question, but if someone else runs in to the same issue that's one way to solve it.

I've built a python program that uses the requests library. It works fine when I run it normally, but not after freezing it to an executable with cx_freeze.

I've already looked at and tried the answers from these questions:

requests library | frozen app | requests & cx_freeze

So neither adding:

import requests.certs
build_exe_options = {"include_files" : [(requests.certs.where(),'cacert.pem')]}

nor

os.environ["REQUESTS_CA_BUNDLE"] = os.path.join(os.getcwd(), "cacert.pem")

are working for me.

My request looks like this:

def get_response(id = constant_id, token = constant_token, page = None):
    url = 'https://scm.commerceinterface.com/api/v2/get_orders'
    return requests.get(url, params = {'supplier_id':id, 'token':token, 'page':page }).json()

so I'm not even passing it the verify = parameter and it works as a python program...

Here is the error(s) returned when I run the executable:

  File "C:\Python34\lib\site packages\requests\packages\urllib3\util\ssl_.py", line 267, in ssl_wrap_socket  
context.load_verify_locations(ca_certs)
FileNotFoundError: [Errno 2] No such file or directory

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\requests\adapters.py", line 370, in send
timeout=timeout
File "C:\Python34\lib\site  
packages\requests\packages\urllib3\connectionpool.p
y", line 539, in urlopen
self._prepare_proxy(conn)
File "C:\Python34\lib\site- 
packages\requests\packages\urllib3\connectionpool.p
y", line 727, in _prepare_proxy
conn.connect()
File "C:\Python34\lib\site- 
packages\requests\packages\urllib3\connection.py",
line 238, in connect
ssl_version=resolved_ssl_version)
File "C:\Python34\lib\site-packages\requests\packages\urllib3\util\ssl_.py", line 269, in ssl_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:\Python34\lib\site-packages\cx_Freeze\initscripts\Console.py", line 
27, in <module> exec(code, m.__dict__)
File "main.py", line 49, in <module>
File "main.py", line 18, in get_response
File "C:\Python34\lib\site-packages\requests\api.py", line 69, in get
return request('get', url, params=params, **kwargs)
File "C:\Python34\lib\site-packages\requests\api.py", line 50, in request
response = session.request(method=method, url=url, **kwargs)
File "C:\Python34\lib\site-packages\requests\sessions.py", line 465, in  
request
resp = self.send(prep, **send_kwargs)
File "C:\Python34\lib\site-packages\requests\sessions.py", line 573, in send
r = adapter.send(request, **kwargs)
File "C:\Python34\lib\site-packages\requests\adapters.py", line 431, in send
raise SSLError(e, request=request) requests.exceptions.SSLError: [Errno 2]  No such file or directory
0

There are 0 best solutions below