Ree*_*Xia 5 python pyinstaller google-cloud-storage google-api-python-client
我编写了一个Python脚本来检查GCS中的文件,它使用wxpython生成GUI。为了进行身份验证,我是以这种方式进行的(遵循Google示例代码中的方法-> 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)
Run Code Online (Sandbox Code Playgroud)
上面的代码包含在我的Python脚本中,当它只是一个python .py文件时效果很好,后来我用pyinstaller在win 7 64bit中将其转换为.exe(我也将秘密文件与.exe文件),使用以下命令
C:\ gcs_file_check> python pyinstaller-2.0 \ pyinstaller.py -w gcs_file_check.py
单击exe时,正确启动了Google 的“ 请求权限”页面(因为它运行的是Python脚本而不是exe),但是单击“接受”后,上面的代码将引发异常:
[Errno 185090050] _ssl.c:343:错误:0B084002:x509证书例程:X509_load_cert_crl_file:系统库
而且我可以看到文件certificate.json不是由.exe创建的,而Python脚本可以正确创建此文件。
有人知道这是怎么发生的以及如何解决吗?感谢每个答案!
===================
于04/16更新:
我添加了调试代码,发现该异常完全来自以下代码:
if credentials is None or credentials.invalid:
credentials = run_oauth2(flow, credential_storage)
Run Code Online (Sandbox Code Playgroud)
===================
更新:
添加更多细节,之前我使用的是oauth2client.tools.run()
from oauth2client.tools import run as run_oauth2
Run Code Online (Sandbox Code Playgroud)
现在,我将建议的源代码更改为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
Run Code Online (Sandbox Code Playgroud)
现在这部分代码是:
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)
Run Code Online (Sandbox Code Playgroud)
但是,尽管如此,python代码仍然运行良好,并且在PyInstaller打包为.exe之后,抛出了相同的异常[Errno 185090050]。
小智 2
试试这个, https: //github.com/kennethreitz/requests/issues/557 “在将 pyinstaller 与 Httplib2 一起使用时,我也遇到了类似的错误。您需要将 ssl 客户端证书文件的路径显式传递给 'cert' 参数 http请求。此外,您还需要将 ..pem 文件打包为 pyinstaller 中的数据文件。”
| 归档时间: |
|
| 查看次数: |
6460 次 |
| 最近记录: |