#StackBounty: #python #google-drive-api #anaconda #google-authentication #pydrive PyDrive 2.0 – AuthenticationError: No code found in r…

Bounty: 200


I’m using PyDrive 2.0 to connect to the Google Drive API.

def connect_google_drive_api():
    # use Gdrive API to access Google Drive
    from pydrive2.auth import GoogleAuth
    from pydrive2.drive import GoogleDrive
    gauth = GoogleAuth()
    gauth.LocalWebserverAuth() # client_secrets.json need to be in the same directory as the script    
    drive = GoogleDrive(gauth)
    return drive

The working directory /Users/mypath/access_google_drive contains the client_secrets.json, which looks like,


where I replaced the real client_id and client_secret with xxx.


When the browser (Safari 14.0) shows Gdrive api link wants to access your Google Account and I click Allow, the process seems to be stuck.

After 20 seconds or so, the following error is shown,

Failed to find "code" in the query parameters of the redirect.
Try command-line authentication
Traceback (most recent call last):

  File "<ipython-input-36-792f41ab7318>", line 1, in <module>

  File "/opt/anaconda3/lib/python3.7/site-packages/pydrive2/auth.py", line 125, in _decorated
    code = decoratee(self, *args, **kwargs)

  File "/opt/anaconda3/lib/python3.7/site-packages/pydrive2/auth.py", line 273, in LocalWebserverAuth
    raise AuthenticationError("No code found in redirect")

AuthenticationError: No code found in redirect

How do I solve this?

Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.