我编写了一个 python 脚本来检查 GCS 中的文件,它使用 wxpython 生成 GUI。为了进行身份验证,我以这种方式做到了(按照 Google 示例代码中的方式 ->http://code.google.com/p/google-cloud-platform-samples/source/browse/file-transfer-json/chunked_transfer.py?repo=storage 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脚本中,当它只是一个python .py文件时效果很好,后来我使用pyinstaller将其转换为win 7 64位中的.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:系统lib
我可以看到该文件凭证.json不是由.exe创建的,而Python脚本可以正确创建该文件。
有人可以知道这是如何发生的以及如何解决吗?赞赏每一个答案!
===================
更新于 04/16:
我添加了调试代码,发现异常正是来自以下代码:
if credentials is None or credentials.invalid:
credentials = run_oauth2(flow, credential_storage)
===================
updated:
添加更多细节,之前我使用过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 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代码运行良好,并在PyInstaller打包到.exe后抛出相同的异常[Errno 185090050]。