python - Google API 和 cx_Freeze 无法正常工作

标签 python openssl google-drive-api cx-freeze

我制作了一个能够将文件上传到 Google 云端硬盘的 Python 程序。 .py 文件完美运行,不会出现任何错误。

但由于我要将它分发给没有安装 Python 的人,我必须将程序和资源转换为 .exe。我用 cx_Freeze 做到了这一点。我以前用过它,它一直有效。

但是现在,Google Drive API 似乎在运行 .exe 时会导致错误。这是它给出的错误:

Traceback (most recent call last):
File "C:\Python27\lib\runpy.py", line 162, in _run_module_as_main
  "__main__", fname, loader, pkg_name)

File "C:\Python27\lib\runpy.py", line 72, in _run_code
  exec code in run_globals

File "Test.py", line 41, in <module>

File "C:\Python27\lib\oauth2client\util.py", line 128, in positional_wrapper
  return wrapped(*args, **kwargs)

File "C:\Python27\lib\oauth2client\client.py", line 1283, in step2_exchange
  headers=headers)

File "C:\Python27\lib\site-packages\httplib2-0.8-py2.7.egg\httplib2\__init__.p
y", line 1570, in request
  (response, content) = self._request(conn, authority, uri, request_uri, metho
d, body, headers, redirections, cachekey)

File "C:\Python27\lib\site-packages\httplib2-0.8-py2.7.egg\httplib2\__init__.p
y", line 1317, in _request
  (response, content) = self._conn_request(conn, request_uri, method, body, he
aders)

File "C:\Python27\lib\site-packages\httplib2-0.8-py2.7.egg\httplib2\__init__.p
y", line 1252, in _conn_request
  conn.connect()

File "C:\Python27\lib\site-packages\httplib2-0.8-py2.7.egg\httplib2\__init__.p
y", line 1021, in connect
  self.disable_ssl_certificate_validation, self.ca_certs)

File "C:\Python27\lib\site-packages\httplib2-0.8-py2.7.egg\httplib2\__init__.p
y", line 80, in _ssl_wrap_socket
  cert_reqs=cert_reqs, ca_certs=ca_certs)

File "C:\Python27\lib\ssl.py", line 383, in wrap_socket
  ciphers=ciphers)

File "C:\Python27\lib\ssl.py", line 141, in __init__
  ciphers)

ssl.SSLError: [Errno 185090050] _ssl.c:340: error:0B084002:x509 certificate rout
ines:X509_load_cert_crl_file:system lib

在用户输入授权码后出现此错误。

经过一番调试,发现是导致这个问题的那一行

credentials = flow.step2_exchange(code)

下面是一段代码:

flow = OAuth2WebServerFlow(CLIENT_ID, CLIENT_SECRET, OAUTH_SCOPE, REDIRECT_URI)
authorize_url = flow.step1_get_authorize_url()
webbrowser.open(authorize_url)
code = raw_input('Enter verification code: ').strip()
credentials = flow.step2_exchange(code)
http = httplib2.Http()
http = credentials.authorize(http)
drive_service = build('drive', 'v2', http=http)

CLIENT_ID、CLIENT_SECRET、OAUTH_SCOPE 和 REDIRECT_URI 均已正确配置。

那么,这里可能是什么问题?

如果您需要查看更多代码,请提问,我会更新此问题。

最佳答案

它似乎无法找到您的 SSL 证书。这是可以理解的,因为 httplib2 从文件系统加载它们,并没有告诉 cx_Freeze 将它们放入 bundle 中。

读这个,它会有所帮助:https://github.com/kennethreitz/requests/issues/557#issuecomment-6420819

关于python - Google API 和 cx_Freeze 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16634671/

相关文章:

python - Django 文件上传输入验证和安全

c - RSA_sign() 段错误不可预测

c - 如何在服务器端使用 openssl 完全禁用重新协商(重新握手)?

android - 将文件上传到 android 中唯一的谷歌驱动器帐户

javascript - Google Drive 上传的外部 Javascript 客户端授权

java - 尝试获取 appDataFolder 中的文件列表时出现 GoogleAuthIOException

python - 如何在 ctypes python 中将 char 指针作为参数传递

安装窗口服务时Python已停止工作(3.7)

python - 将计算列添加到 pandas 数据透视表

c - 数字信封例程:EVP_DecryptFinal_ex:wrong final block length:evp_enc in C program