编程语言
首页 > 编程语言> > python – 请求库:在cx_Freeze之后缺少SSL握手证书文件

python – 请求库:在cx_Freeze之后缺少SSL握手证书文件

作者:互联网

我正在使用请求库在python 3.3中构建一个应用程序.
当我尝试获取具有SSL连接的URL时,我想使用verify = true验证它.
这在运行我的python脚本时非常有效.

当我冻结相同的脚本时,它会崩溃.它错过了一些东西,我真的无法弄清楚如何将它集成到我的冻结应用程序中.

我收到以下错误(这也会触发其他错误,但我不在这里发布):

Traceback (most recent call last):
File "C:\Python33-32\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 422, in urlopen
body=body, headers=headers)
File "C:\Python33-32\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 274, in _make_request
conn.request(method, url, **httplib_request_kw)
File "C:\Python33-32\lib\http\client.py", line 1049, in request
self._send_request(method, url, body, headers)
File "C:\Python33-32\lib\http\client.py", line 1087, in _send_request
self.endheaders(body)
File "C:\Python33-32\lib\http\client.py", line 1045, in endheaders
self._send_output(message_body)
File "C:\Python33-32\lib\http\client.py", line 890, in _send_output
self.send(msg)
File "C:\Python33-32\lib\http\client.py", line 828, in send
self.connect()
File "C:\Python33-32\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 105, in connect
ssl_version=self.ssl_version)
File "C:\Python33-32\lib\site-packages\requests\packages\urllib3\util.py", line 281, in ssl_wrap_socket
context.load_verify_locations(ca_certs)
FileNotFoundError: [Errno 2] No such file or directory 

似乎缺少ca_certs.在请求库中有一个名为cacert.pem的文件,但我不知道这是否是丢失的文件以及如何导入它,因为它似乎没有集成到我的最终冻结包中.

解决方法:

查看请求源,似乎您可以将路径传递给cacert.pem文件作为verify = path,而不是verify = True.因此,您无需修改​​其工作请求.

您可以传递文件的路径以包含在cx_Freeze选项的include-files参数中(docs).你可以从请求中找到路径,所以这样的东西应该在你用来冻结它的setup.py中起作用:

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

#...

标签:python,python-requests,cx-freeze
来源: https://codeday.me/bug/20190918/1810293.html