gpt4 book ai didi

python - 我如何告诉 pyinstaller 使用带有 --onefile 选项的 python-certifi-win32

转载 作者:行者123 更新时间:2023-12-05 01:29:23 35 4
gpt4 key购买 nike

我有一个小脚本,它使用 tableau rest api 从 tableau View 下载数据。由于脚本在公司环境中运行,因此我必须使用 SSL。那就是 python-certifi-win32 的地方包开始发挥作用。使用 pip install python-certifi-win32 安装包修补 certifi 包以使用本地机器证书存储。来自文档:

This package patches certifi at runtime to also include certificates from the windows certificate store.

当我从源代码运行脚本时,这工作得很好,但如果我使用 pyinstaller(使用 --onefile 选项)创建可执行文件,“运行时补丁”似乎不会发生我收到“无法验证本地证书”错误,这与我在安装 python-certifi-win32 软件包之前遇到的错误相同。

由于我是 Python 的新手,我无法弄清楚 python-certifi-win32 包究竟是如何执行“运行时补丁”的。我已经尝试使用 --hidden-import 选项,但没有用。

关于如何告诉 pyinstaller(或我的脚本)在作为可执行文件调用时应用“python-certifi-win32 魔法”的任何建议?

最佳答案

您不需要弄乱隐藏的导入,但您需要导入库本身。

在 PyInstaller 的运行时设置中执行时,包会失去一些自动魔法。解决这个问题取决于你在哪里需要 winstore 证书,但这是我为了让它在我需要它的地方工作而做的 requests :

if sys.platform == 'win32':
import certifi_win32
os.environ['REQUESTS_CA_BUNDLE'] = certifi_win32.wincerts.where()
certifi_win32.generate_pem()

设置REQUESTS_CA_BUNDLE将指向使用 certifi_win32 创建的商店的请求。 generate_pem函数将结合 PyInstaller 附带的证书包(位于 <MEIPASS>\certifi )和 wincert 商店。结果 pem文件被写入 %LOCALAPPDATA%/.certifi/cacert.pem .

关于python - 我如何告诉 pyinstaller 使用带有 --onefile 选项的 python-certifi-win32,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67803957/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com