使用 cx_freeze 转换为 *.exe 时出现 SSL 异常
Posted
技术标签:
【中文标题】使用 cx_freeze 转换为 *.exe 时出现 SSL 异常【英文标题】:SSL exception while converting to *.exe with cx_freeze 【发布时间】:2016-05-25 08:38:59 【问题描述】:使用 cx_freeze 将我的程序转换为 EXE 后,出现以下错误:
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
即使我没有明确使用 requests 库,我也认为 Genderize 确实如此。所以我已经阅读了几篇关于它的帖子,并试图将路径传递给我的 cacert.pem 文件,但它仍然不能解决我的问题。这就是我格式化 setup.py 文件的方式:
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])
我在 Windows 7 64 位上使用 Python 3.4.4。知道我做错了什么吗?
【问题讨论】:
【参考方案1】:您可以尝试按照here 和here 的描述将您的证书添加为环境变量。
os.environ["REQUESTS_CA_BUNDLE"] = os.path("/path/to/cacert.pem")
但是你尝试过的应该也可以。
【讨论】:
哈!有效!我不确定为什么其他解决方案没有完成这项工作,但我很高兴它现在解决了。谢谢!以上是关于使用 cx_freeze 转换为 *.exe 时出现 SSL 异常的主要内容,如果未能解决你的问题,请参考以下文章
使用 cx_freeze 将 .py 转换为 .exe 时出错
使用 cx_Freeze 时出现问题:“无法导入名称 'tf2'”
使用 cx_freeze 将脚本转换为 .exe 时如何包含 tkinter?
使用 cx_Freeze 将 Python 转换为 exe 时 Scipy 和 Cython 出现 AttributeError