修改
所以我最后只使用了Portable Python。我的目标是在没有安装Python的Windows Server上运行Python脚本,这就是PP可以做的事情。这不是我原来问题的真正解决方案,但如果有其他人遇到同样的问题,这是解决问题的一种方法。
我已经构建了一个使用请求库的python程序。它在我正常运行时工作正常,但在使用cx_freeze将其冻结为可执行文件后却没有。
我已经看过并尝试过这些问题的答案:
requests library | frozen app | requests & cx_freeze
所以既不添加:
import requests.certs
build_exe_options = {"include_files" : [(requests.certs.where(),'cacert.pem')]}
,也不
os.environ["REQUESTS_CA_BUNDLE"] = os.path.join(os.getcwd(), "cacert.pem")
正在为我工作。
我的请求如下:
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()
所以我甚至没有传递verify =参数,它可以作为python程序......
以下是运行可执行文件时返回的错误:
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