Python谷歌api

Python谷歌api,python,python-2.7,google-api,Python,Python 2.7,Google Api,我试图学习google api,我的经验是使用Python,因此我试图使用google api Python客户端访问google的一些服务,但在构建服务对象时遇到了一个错误 从apiclient.discovery导入生成模块没有问题: >>> from apiclient.discovery import build >>> 但是当需要构建服务对象时(就像我下载的教程文件中所做的那样),有些东西崩溃了,我无法找出哪里出了问题 >>> s

我试图学习google api,我的经验是使用Python,因此我试图使用google api Python客户端访问google的一些服务,但在构建服务对象时遇到了一个错误

从apiclient.discovery导入生成模块没有问题:

>>> from apiclient.discovery import build
>>>
但是当需要构建服务对象时(就像我下载的教程文件中所做的那样),有些东西崩溃了,我无法找出哪里出了问题

>>> service = build('books','v1',developerKey=api_key)
WARNING:root:No module named locked_file
Traceback (most recent call last):
  File "build/bdist.macosx-10.10-intel/egg/googleapiclient/discovery_cache/__init__.py", line 38, in autodetect
    from . import file_cache
  File "build/bdist.macosx-10.10-intel/egg/googleapiclient/discovery_cache/file_cache.py", line 32, in <module>
ImportError: No module named locked_file
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "build/bdist.macosx-10.10-intel/egg/oauth2client/util.py", line 140, in positional_wrapper
  File "build/bdist.macosx-10.10-intel/egg/googleapiclient/discovery.py", line 196, in build
  File "build/bdist.macosx-10.10-intel/egg/googleapiclient/discovery.py", line 242, in _retrieve_discovery_doc
  File "/Library/Python/2.7/site-packages/httplib2-0.9.2-py2.7.egg/httplib2/__init__.py", line 1609, in request
    (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
  File "/Library/Python/2.7/site-packages/httplib2-0.9.2-py2.7.egg/httplib2/__init__.py", line 1351, in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)
  File "/Library/Python/2.7/site-packages/httplib2-0.9.2-py2.7.egg/httplib2/__init__.py", line 1272, in _conn_request
    conn.connect()
  File "/Library/Python/2.7/site-packages/httplib2-0.9.2-py2.7.egg/httplib2/__init__.py", line 1036, in connect
    self.disable_ssl_certificate_validation, self.ca_certs)
  File "/Library/Python/2.7/site-packages/httplib2-0.9.2-py2.7.egg/httplib2/__init__.py", line 80, in _ssl_wrap_socket
    cert_reqs=cert_reqs, ca_certs=ca_certs)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 911, in wrap_socket
    ciphers=ciphers)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 520, in __init__
    self._context.load_verify_locations(ca_certs)
IOError: [Errno 13] Permission denied
>>>
>service=build('books','v1',developerKey=api_)
警告:root:没有名为locked_file的模块
回溯(最近一次呼叫最后一次):
文件“build/bdist.macosx-10.10-intel/egg/googleapiclient/discovery_cache/_init__.py”,第38行,自动检测
从…起导入文件缓存
文件“build/bdist.macosx-10.10-intel/egg/googleapiclient/discovery_cache/File_cache.py”,第32行,在
ImportError:没有名为locked_file的模块
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
文件“build/bdist.macosx-10.10-intel/egg/oauth2client/util.py”,第140行,在位置包装器中
文件“build/bdist.macosx-10.10-intel/egg/googleapiclient/discovery.py”,第196行,内部版本
文件“build/bdist.macosx-10.10-intel/egg/googleapiclient/discovery.py”,第242行,位于“检索发现”文档中
请求中的文件“/Library/Python/2.7/site packages/httplib2-0.9.2-py2.7.egg/httplib2/_init__;.py”,第1609行
(响应,内容)=self.\u请求(conn,authority,uri,request\u uri,method,body,header,重定向,cachekey)
文件“/Library/Python/2.7/site packages/httplib2-0.9.2-py2.7.egg/httplib2/__init___;.py”,第1351行,在请求中
(响应,内容)=自连接请求(连接,请求uri,方法,正文,标题)
文件“/Library/Python/2.7/site packages/httplib2-0.9.2-py2.7.egg/httplib2/_init__.py”,第1272行,在连接请求中
连接
文件“/Library/Python/2.7/site packages/httplib2-0.9.2-py2.7.egg/httplib2/__init___;.py”,第1036行,在connect中
self.disable\u ssl\u证书\u验证,self.ca\u证书)
文件“/Library/Python/2.7/site packages/httplib2-0.9.2-py2.7.egg/httplib2/_init__.py”,第80行,在ssl_wrap_套接字中
证书要求=证书要求,ca证书=ca证书)
文件“/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py”,第911行,在wrap_套接字中
密码=密码)
文件“/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py”,第520行,在__
self.\u context.加载\u验证\u位置(ca证书)
IOError:[Errno 13]权限被拒绝
>>>
以下是我如何做到这一点的,以防它有所帮助:我开始安装客户端库和它所依赖的所有其他模块,如下所述:。我使用了pip(和必要的sudo),一切都进行得很顺利。我已经尝试通过使用pip的--update参数更新模块来修复我的错误,但这似乎不是问题,因为所有模块都说“需求已经是最新的:{Name of Module Document Here}”,所以我认为这不是问题所在

之后,我开始学习教程。在本教程中,它给出了与google books接口的示例API(这给我带来了麻烦)。正如本教程开头所述,我从google获得了一个API开发者密钥,我认为这不是问题所在,因为我甚至没有执行服务对象

我在谷歌上搜索了这个错误,但没有发现任何人有类似的问题,所以我希望这里的人能帮助我

谢谢

MLP

看起来您的权限有问题。 制作
chown“用户名”“python文件”


或者
chown-R'username''目录名'

此处相同,似乎oauth2client 2.0中没有锁定文件

  >>> from oauth2client.locked_file import LockedFile    
  Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
  ImportError: No module named locked_file
>>从oauth2client.locked\u文件导入LockedFile
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
ImportError:没有名为locked_file的模块

我还在github上发现了一个未解决的问题。这是一个google api python客户端错误:

我刚刚尝试了chown(在文件/dir上,api是正确的吗?不是模块或任何东西?),但得到了相同的错误:(以下是它运行的python文件的权限:“-rw-r--r--1 mlp staff 2271 Feb 18 00:54 GoogleBooksExample.py”,这是它之前在回溯中提到的模块的权限“-rw-r--r--1 root wheel 36583 Jul 14 2015 ssl.py”@MLP,如果使用管理员权限运行脚本会怎么样?它会工作吗?它刚刚在主分支中得到修复
  >>> from oauth2client.locked_file import LockedFile    
  Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
  ImportError: No module named locked_file