编程语言
首页 > 编程语言> > python – Google API和cx_Freeze无法正常工作

python – Google 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(代码)

以下是代码片段:

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将它们放在捆绑的包中.

阅读本文,它将有所帮助:https://github.com/kennethreitz/requests/issues/557#issuecomment-6420819

标签:python,openssl,cx-freeze,google-drive-api
来源: https://codeday.me/bug/20190831/1779246.html