Python Google API - python

我正在尝试学习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
>>>

如果有帮助,我将按照以下步骤进行操作:首先安装客户端库和它所依赖的所有其他模块,如下所示:Google API Python Installation。我使用了pip(和必要的sudo),一切都畅游了。我尝试通过使用pip的--update参数更新模块来修复错误,但这似乎不是问题,因为它们所有人都说“要求已经是最新的:{此处的模块文档名称}”,所以我不相信这是问题所在。

之后,我开始关注本教程。在本教程中,它提供了示例API(给我带来麻烦)与Google图书的接口:Google Books Example。我已从Google那里获得了本教程开始部分概述的API开发人员密钥,但我不认为这是问题所在,因为我什至没有执行服务对象。

我搜索了该错误,但没有看到有类似问题的任何人,因此希望这里的人能为您提供帮助!

谢谢,

MLP

参考方案

同样在这里,似乎在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

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

通过Python使用FacePlusPlus API - python

我收到以下错误。'error_message': 'BAD_ARGUMENTS 当我执行此python代码时。import requests import json response = requests.post( 'https://api-us.faceplusplus.com/facepp/v3/detect&#…

我需要帮助将此REST API Curl命令转换为Python请求 - python

我在这里是新手,老实说对所有编码都是新手。我正在尝试创建一个Pyton脚本,以使用REST API从Request Tracker资产数据库中搜索项目。到目前为止,我得到了以下Curl命令:curl -X POST \ -H "Content-Type: application/json" \ -d '[{ "fiel…

Python-使用请求时发布请求失败 - python

使用外壳程序时,我可以通过运行以下命令成功创建新用户curl --user administrator:pasword "Content-Type: application/json" https://localhost:8080/midpoint/ws/rest/users -d @user.json但是,当我尝试使用请求在python…

Python uuid4,如何限制唯一字符的长度 - python

在Python中,我正在使用uuid4()方法创建唯一的字符集。但是我找不到将其限制为10或8个字符的方法。有什么办法吗?uuid4()ffc69c1b-9d87-4c19-8dac-c09ca857e3fc谢谢。 参考方案 尝试:x = uuid4() str(x)[:8] 输出:"ffc69c1b" Is there a way to…

如何在邮递员的正文中输入两个输入 - python

@api_view(["POST"]) def Addition(x): number1=json.loads(x.body) addition=str(number1+6) return JsonResponse(" Addition is :"+addition+".",safe=False) …