我正在尝试cx_freeze依赖于请求的python应用程序,但是我收到以下错误:
File "C:\Python33\lib\site-packages\requests-2.5.3-py3.3.egg\requests\api.py",
line 65, in get
return request('get', url, **kwargs)
File "C:\Python33\lib\site-packages\requests-2.5.3-py3.3.egg\requests\api.py",
line 49, in request
response = session.request(method=method, url=url, **kwargs)
File "C:\Python33\lib\site-packages\requests-2.5.3-py3.3.egg\requests\sessions
.py", line 461, in request
resp = self.send(prep, **send_kwargs)
File "C:\Python33\lib\site-packages\requests-2.5.3-py3.3.egg\requests\sessions
.py", line 573, in send
r = adapter.send(request, **kwargs)
File "C:\Python33\lib\site-packages\requests-2.5.3-py3.3.egg\requests\adapters
.py", line 431, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: [Errno 2] No such file or directory
这个简单的脚本一切正常:
import requests
url = 'https://test.com'
try:
res = requests.get(url, headers={'User-Agent': self.user_agent},timeout=10)
redirecturl = res.url
code = res.status_code
except requests.exceptions.ConnectTimeout as err:
print ("error -%s" %err)
cx_freeze setup.py
from cx_Freeze import setup, Executable
import sys
build_exe_options = {"package":["requests"],"excludes" : "[Tkinter]"}
base = None
if sys.platform == "win32":
none = "Win32GUI"
setup(
name ="PageFound",
version ="1.0",
description ="PageFound Tool",
options = {"buid_exe": build_exe_options},
executables=[Executable("PageFound.py")])
如果有人能给我一个提示,我将不胜感激。
答案 0 :(得分:0)
未找到验证ssl证书所需的文件,因为当您冻结它时,该特定文件不会随构建一起冻结。然后请求在其默认位置寻找它并且在那里找不到它。这是因为当您运行脚本而不被冻结时,它可以正常工作,但是当目录更改时,它不会。有人else比我更好:
查看请求源,似乎可以将路径传递给 cacert.pem文件为verify = path,而不是verify = True。所以你没有 需要修改它的工作请求。
您可以传递文件的路径以包含在包含文件中 cx_Freeze选项的参数(docs)。你可以找到路径 请求,所以这样的东西应该在你使用的setup.py中工作 冻结它:
导入requests.certs
build_exe_options = { “include_files”:[(requests.certs.where(), 'cacert.pem')]}
...