Martel
Martel

Reputation: 2734

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

Upvotes: 6

Views: 1840

Answers (3)

adeler
adeler

Reputation: 151

Actually adding the code mentioned above fixes the problem entirely.

import logging
logging.basicConfig(filename='debug.log',level=logging.DEBUG)

Upvotes: 0

John Mee
John Mee

Reputation: 52253

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.

Upvotes: 5

Martel
Martel

Reputation: 2734

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.

Upvotes: 1

Related Questions