Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error trying to access "google drive" with python (google quickstart.py source code)

I'm trying to learn how to access Google Drive from Python but I have problems.

I followed the tutorial of google's official website: https://developers.google.com/drive/...t-python?hl=es In addition, i have seen the video tutorial about this, I think I do the same than the video guys exactly.

I tell you the steps I've followed literally:

1 - Install pip tool to install the SDK from Google.

2 - Install the SDK from Google: "pip install --upgrade google-api-python-client"

In this step all goes well, in fact to make imports etc. there is no fault.

3 - Drive Enable API: I follow the steps as is, create a "client ID for native application" and a "client ID for web application "

4 - I create the document "document.txt" and copy the source code as it quickstart.

5 - I replace "CLIENT_ID" and "CLIENT_SECRET" by appearing in "Client id for native application" (I've also tested with web application)

6 - I run, and screen output is:

No handlers could be found for logger "oauth2client.util"
Go to the following link in your browser:
<link>
Enter verification code:

Looking for a solution, i found something to get some information about that error:

import logging
...
logging.basicConfig()

Now, the output is:

C:\workspaces\asd\prsGoogleApi>quickstart.py
WARNING:oauth2client.util:__init__() takes at most 4 positional arguments (5 giv
en)
Go to the following link in your browser:
<link>
Enter verification code:

If I try to access that link, the error is:

401 - That's an error
Error: invalid_client.
No application name.

Request details:
response_type=code
scope=https://www.googleapis.com/auth/drive
access_type=offline
redirect_uri=urn:ietf:wg:oauth:2.0:oob
client_id=...
like image 940
Dan Avatar asked Sep 11 '14 11:09

Dan


People also ask

How do I use Google Drive API with Python?

Enable the Drive API Download your credentials by clicking the "Download Client Configuration" button and then "Done". Finally, you need to put credentials. json that is downloaded into your working directories (i.e., where you execute the upcoming Python scripts).

Is Google Drive API free?

Pricing. All use of the Drive API is available at no additional cost.


2 Answers

The module in question oauthclient.util makes some assumptions that there is logging established and this warning is actually masking a more detailed warning/error which it tried to write to the log.

If you add some logging to your own code then it should reveal the underlying error:

import logging
logging.basicConfig()

was enough to replace the appearance of the above error with the true error in my output (YMMV).

Once that's resolved you can probably remove these two lines safely (although you'll probably wind up back here should something else go wrong).

This question came up in a google search for No handlers could be found for logger "oauth2client.util" alongside this issue and this issue.

like image 71
John Mee Avatar answered Sep 19 '22 00:09

John Mee


I have found the problem, it was that I had not put my email address and client name at "Consent screen" section.

Now it works good.

like image 38
Dan Avatar answered Sep 22 '22 00:09

Dan