Python google api

MLP*_*MLP 5 python google-api python-2.7

我正在尝试学习谷歌API,我的经验是用Python,所以我试图使用谷歌api python客户端访问一些谷歌的服务,但我遇到一个错误构建服务对象.

从apiclient.discovery导入构建模块没有问题:

>>> from apiclient.discovery import build
>>>
Run Code Online (Sandbox Code Playgroud)

但是到了构建服务对象的时候(就像我下载的教程文件中所做的那样),崩溃了,我无法弄清楚出了什么问题!

>>> 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
>>>
Run Code Online (Sandbox Code Playgroud)

以下是我如何做到这一点,以防它有用:我开始安装客户端库和它所依赖的所有其他模块,如下所述:Google API Python安装.我使用了pip(和必要的sudo),一切都顺其自然.我已经尝试通过使用pip的--update参数更新模块来修复我的错误,但这似乎不是问题,因为所有人都说" 要求已经是最新的: {模块文档名称}"所以我不相信这是问题所在.

之后,我开始学习本教程.在本教程中,它提供了与Google图书界面接口的示例API(这给我带来了麻烦):Google图书示例.我从本教程开头概述的谷歌获得了API开发人员密钥,我不相信这是问题,因为我甚至没有执行服务对象.

我用Google搜索了错误,但没有看到任何有类似问题的人,所以我希望这里的人可以提供帮助!

谢谢,

MLP

小智 5

同样在这里,似乎oauth2client 2.0中没有LockedFile

  >>> from oauth2client.locked_file import LockedFile    
  Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
  ImportError: No module named locked_file
Run Code Online (Sandbox Code Playgroud)

我也在github发现了一个未解决的问题.这是一个google-api-python-client错误:https://github.com/google/google-api-python-client/issues/179


noi*_*ise 0

IOError: [Errno 13] Permission denied
Run Code Online (Sandbox Code Playgroud)

看来您在权限方面遇到了问题。制作chown 'username' 'python file'

或者chown -R 'username' 'directory name'