Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python google api

I am trying to learn google APIs and my experience is with Python so I'm trying to use the google api python client to access some of google's services but am encountering an error building the service object.

There's no problem importing the build module from apiclient.discovery:

>>> from apiclient.discovery import build
>>>

But when it comes time to build the service object (as done in the tutorial file that I downloaded), something crashes and I can't figure out what's going wrong!

>>> 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
>>>

Here's how I got to this point in case it's helpful: I began by installing the client library and all other modules that it depended on as outlined here : Google API Python Installation. I used pip (and the necessary sudo) and everything went swimmingly. I have tried fixing my error by updating the modules with pip's --update argument but that doesn't appear to be the problem as all of them say "Requirement already up-to-date: {Name of Module Document Here}" so I don't believe that's the problem.

After that, I began following the tutorial. In the tutorial, it gives the example API (that's giving me trouble) to interface with google books: Google Books Example. I got an API developer key from google as outlined in the beginning of the tutorial and I don't believe that's the problem as I'm not even executing the service object.

I googled the error but didn't see anyone with similar problems so I hope people here can help!

Thanks,

MLP

like image 673
MLP Avatar asked Feb 18 '16 07:02

MLP


People also ask

Does Google have a Python API?

Get the list of google resources from the Google API Python Github. <API-VERSION> defines the version provided by Google for specific Google resources, get more information from the official documentation.

Can API be made with Python?

There are different ways to create an API in Python, the most used being FastAPI and Flask.

Can we import Google in Python?

Using python package google we can get results of google search from the python script. We can get links to first n search results.


1 Answers

same here, it seems that there is not a LockedFile in the 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

also i found an open issue at github. It is a google-api-python-client error: https://github.com/google/google-api-python-client/issues/179

like image 122
vfiebig Avatar answered Oct 05 '22 13:10

vfiebig