请求库:cx_Freeze 后缺少 SSL 握手证书文件 [英] Requests library: missing SSL handshake certificates file after cx_Freeze

查看:16
本文介绍了请求库:cx_Freeze 后缺少 SSL 握手证书文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm building an application in python 3.3 which uses the requests library. When I try to get a URL with SSL connection I want to verify it with verify = true. This works perfectly when running my python scripts.

当我冻结相同的脚本时,它会崩溃.它遗漏了一些东西,我真的不知道如何将它集成到我冻结的应用程序中.

When I freeze the same scripts it crashes. It misses something and I really cant figure out how to integrate it in my frozen application.

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

I get the following error (which also triggers other errors, but I don't post them here):

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

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

It seems that ca_certs is missing. There is a file called cacert.pem in the requests library, but I don't know if this is the missing file and how to import it since it seems to be not integrated into my final frozen package.

推荐答案

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

Looking at the requests source, it seems you can pass the path to the cacert.pem file as verify=path, instead of verify=True. So you don't need to modify requests for it to work.

您可以传递要包含在 cx_Freeze 选项的 include-files 参数中的文件路径 (docs).您可以从请求中找到路径,因此这样的内容应该可以在用于冻结它的 setup.py 中工作:

You can pass the path of a file to include in the include-files parameter of the cx_Freeze options (docs). You can find the path from requests, so something like this should work in the setup.py you use to freeze it:

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

#...

这篇关于请求库:cx_Freeze 后缺少 SSL 握手证书文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆