使用 cx_freeze 转换为 *.exe 时出现 SSL 异常
SSL exception while converting to *.exe with cx_freeze
使用 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
尽管我没有明确地使用请求库,但我假设 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。知道我做错了什么吗?
您可以尝试将您的证书添加为环境变量,如here and here所述。
os.environ["REQUESTS_CA_BUNDLE"] = os.path("/path/to/cacert.pem")
但是您尝试过的应该也有效。
使用 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
尽管我没有明确地使用请求库,但我假设 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。知道我做错了什么吗?
您可以尝试将您的证书添加为环境变量,如here and here所述。
os.environ["REQUESTS_CA_BUNDLE"] = os.path("/path/to/cacert.pem")
但是您尝试过的应该也有效。