Errno 185090050 _ssl.c:343: error:0B084002:x509证书例程:X509_load_cert_crl_file:系统库,使用PyInstaller打包为exe后

5 投票
1 回答
8605 浏览
提问于 2025-04-18 02:45

我写了一个Python脚本,用来检查GCS(谷歌云存储)里的文件,使用wxpython来生成图形界面。为了进行身份验证,我是按照谷歌示例代码的方式来做的,具体可以参考这个链接:http://code.google.com/p/google-cloud-platform-samples/source/browse/file-transfer-json/chunked_transfer.py?repo=storage

flow = flow_from_clientsecrets(CLIENT_SECRETS_FILE, 
                                # the secrets file I put in same folder
                               scope=scope,
                               message=MISSING_CLIENT_SECRETS_MESSAGE)

credential_storage = CredentialStorage(CREDENTIALS_FILE) # the file to store
                                                    # authentication credentials
credentials = credential_storage.get()
if credentials is None or credentials.invalid:
    credentials = run_oauth2(flow, credential_storage)

self.printLog('Constructing Google Cloud Storage service...')
http = credentials.authorize(httplib2.Http())
return discovery_build('storage', 'v1beta1', http=http)

上面的代码包含在我的Python脚本里,当它只是一个.py文件时运行得很好。后来我用pyinstaller把它转换成了.exe文件,适用于Windows 7 64位(我还把密钥文件放在和.exe文件同一个文件夹里),使用的命令是:

C:\gcs_file_check>python pyinstaller-2.0\pyinstaller.py -w gcs_file_check.py

当我点击这个.exe文件时,谷歌的权限请求页面正确地弹出来了(就像运行Python脚本时那样),但在我点击接受后,上面的代码就抛出了一个异常:

[Errno 185090050] _ssl.c:343: error:0B084002:x509 certificate routines:X509_load_cert_crl_file:system lib

我发现credentials.json这个文件没有被.exe创建,而Python脚本能够正确创建这个文件。

有人知道这是怎么回事吗?怎么解决这个问题呢?非常感谢每一个回答!

===================

更新于04/16:

我添加了调试代码,发现异常确实来自下面的代码:

if credentials is None or credentials.invalid:
    credentials = run_oauth2(flow, credential_storage)

===================

更新:

补充更多细节,之前我使用的是oauth2client.tools.run()

from oauth2client.tools import run as run_oauth2

现在我改用了run_flow(),正如源代码所建议的那样 -> https://google-api-python-client.googlecode.com/hg/docs/epy/oauth2client.tools-pysrc.html#run

from oauth2client.tools import run_flow as run_oauth2

现在这部分代码是:

parser=argparse.ArgumentParser(description=__doc__,                  
                     formatter_class=argparse.RawDescriptionHelpFormatter,
                     parents=[tools.argparser] )
                     flags = tools.argparser.parse_args(sys.argv[1:])

if credentials is None or credentials.invalid:
    credentials = run_oauth2(flow, credential_storage, flags)

但是仍然,Python代码运行得很好,打包成.exe后,使用PyInstaller时仍然抛出同样的异常 [Errno 185090050]。

1 个回答

2

试试这个,https://github.com/kennethreitz/requests/issues/557。 “我在用pyinstaller和Httplib2的时候也遇到过类似的错误。你需要明确地把ssl客户端证书文件的路径传给http请求的'cert'参数。此外,你还需要把你的.pem文件作为数据文件打包进pyinstaller。”

撰写回答