Google API和cx_Freeze无法正常工作 [英] Google API and cx_Freeze not working properly

查看:485
本文介绍了Google API和cx_Freeze无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



但是,因为我要将它分发给没有安装Python的人,所以我必须将程序和资源放入.exe。我用cx_Freeze做了这个。我以前使用它,它一直工作。



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

pre code $ Traceback最近一次调用最后一次
文件C:\Python27 \lib\runpy.py,第162行,在_run_module_as_main
__main__,fname,loader,pkg_name)

文件C:\Python27\lib\runpy .py,第72行,在_run_code中
在run_globals中执行代码

在< module>文件中的第41行Test.py

文件C:\Python27\lib\oauth2client\util.py,第128行,位置位置
返回包裹(*参数,** kwargs)

文件C:\Python27\lib\oauth2client\client.py,第1283行,在step2_exchange
headers = headers)

文件C: \Python27\lib\site-packages\httplib2-0.8-py2.7.egg\httplib2\__init __。p
y,第1570行,请求
(response,content) = self._request(conn,authority,uri,request_uri,metho
d,body,headers,redirections,cachekey)

文件C:\Python27\lib\site-packages \httplib2-0.8-py2.7.egg\httplib2\__init __。p
y,第1317行,在_request
(response,content)= self._conn_request(conn,request_uri,method, body,他
aders)

文件C:\Python27\lib\site-packages\httplib2-0.8-py2.7.egg\httplib2\__init__。 p
y,第1252行,在_conn_request
conn.connect()

Fi leC:\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)

文件C:\Python27\lib\site-packages\httplib2-0.8-py2.7.egg\httplib2\__init __。p
y,第80行,位于_ssl_wrap_socket
cert_reqs = cert_reqs,ca_certs = ca_certs)

文件C:\Python27\lib\ssl.py,第383行, in wrap_socket
ciphers = ciphers)

文件C:\Python27\lib\ssl.py,第141行,在__init__
密码)

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

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



经过一些调试后,我发现导致这个问题的线路是:

$ p $ c> 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代码:').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


I have made a Python program that is capable of uploading files into Google Drive. The .py file works perfectly and does not give any errors.

But as I'm going to distribute it for people who do not have Python installed, I must turn the program and the resources into a .exe. I have done this with cx_Freeze. I have used it before and it has always worked.

But now, the Google Drive API seems to be causing errors when the .exe is run. Here are the errors it gives:

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

It gives this error after the user has typed in the authorization code.

After some debugging, I found out that the line causing this problem was

credentials = flow.step2_exchange(code)

Here is a snippet of the 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)

The CLIENT_ID, CLIENT_SECRET, OAUTH_SCOPE and REDIRECT_URI are all configured correctly.

So, what could be the problem here?

If you need to see more code, ask and I will update this question.

解决方案

Looks like it can't find your SSL certificates. This is kind of understandable because httplib2 loads them from the file system, and nothing tells cx_Freeze to put them in the bundled package.

Read this, it will help: https://github.com/kennethreitz/requests/issues/557#issuecomment-6420819

这篇关于Google API和cx_Freeze无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆