Fail to authenticate with pydrive to google drive

2.3k Views Asked by At

I am following the instruction to use PyDrive on this documentation link and after running this part

from pydrive.auth import GoogleAuth

gauth = GoogleAuth()
gauth.LocalWebserverAuth() # Creates local webserver and auto handles authentication.

everything seems to work fine, my browser opens and I need to authenticate with my Gmail account. But after accepting the last part the process loads and I get an error message in the browser Safari Screenshot it's German and it basically says that safari wasn't able to connect to localhost:8080.

In the terminal I get this Traceback:

Failed to find "code" in the query parameters of the redirect.
Try command-line authentication
Traceback (most recent call last):
  File "/Users/gepluse/CodeProjects/ComunioBuster/test2.py", line 4, in <module>
    gauth.LocalWebserverAuth()  # Creates local webserver and auto handles authentication.
  File "/Users/gepluse/CodeProjects/ComunioBuster/venv/lib/python3.8/site-packages/pydrive/auth.py", line 115, in _decorated
    code = decoratee(self, *args, **kwargs)
  File "/Users/gepluse/CodeProjects/ComunioBuster/venv/lib/python3.8/site-packages/pydrive/auth.py", line 241, in LocalWebserverAuth
    raise AuthenticationError('No code found in redirect')
pydrive.auth.AuthenticationError: No code found in redirect

I also followed this tutorial link and I checked every step I made several times without any success.

In some posts here the firewall was the issue but the firewall on my Mac isn't activated.

I'm running macOS 10.15.7 / Python 3.8.3 / PyDrive 1.3.1

1

There are 1 best solutions below

1
On BEST ANSWER

I made changes according to this Solution by Dano. The save and load of mycreds.txt helped to solve this issue.