You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python脚本经PyInstaller编译后在Windows服务器遇SSL证书验证错误求助

PyInstaller打包后XML-RPC连接Odoo出现SSL主机名不匹配错误的解决办法

以下是针对你遇到的问题的可行解决思路:

  • 确保所有XML-RPC请求都应用未验证上下文
    若你仅给common接口设置了未验证上下文,但后续调用object接口时未复用该上下文,仍会触发验证。需确保所有ServerProxy实例都使用同一个SSL上下文:

    import ssl
    import xmlrpc.client
    
    URL = "https://xxx.dev.odoo.com"
    # 创建全局未验证SSL上下文
    ssl_context = ssl._create_unverified_context()
    # 初始化common接口
    common = xmlrpc.client.ServerProxy(f"{URL}/xmlrpc/2/common", context=ssl_context)
    # 初始化object接口(如果用到的话)
    models = xmlrpc.client.ServerProxy(f"{URL}/xmlrpc/2/object", context=ssl_context)
    
  • 强制关闭主机名检查
    部分场景下,仅创建未验证上下文还不够,需显式关闭主机名验证:

    ssl_context = ssl._create_unverified_context()
    ssl_context.check_hostname = False
    
  • PyInstaller打包时强制包含SSL依赖
    PyInstaller可能未自动包含SSL相关模块或证书文件,打包时添加参数确保依赖被正确打包:

    pyinstaller --hidden-import ssl your_script.py
    

    若存在证书路径问题,可手动将系统CA证书打包到程序中,运行时指定证书路径:

    import ssl
    import sys
    import os
    
    # 获取打包后的资源目录
    cert_path = os.path.join(sys._MEIPASS, "ca-bundle.crt")
    ssl_context = ssl.create_default_context(cafile=cert_path)
    

    打包命令需添加证书文件:

    pyinstaller --add-data "C:\Windows\System32\certificates\ca-bundle.crt;." your_script.py
    

    (注:ca-bundle.crt的路径需根据你的Windows系统实际位置调整)

  • 检查URL与证书主机名完全匹配
    确认代码中使用的URL主机名(如xxx.dev.odoo.com)与证书绑定的主机名完全一致,避免拼写错误、多/少前缀(如www)等问题。

内容的提问来源于stack exchange,提问作者Tony

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 16:23:29