google-auth-library-python-oauthlib icon indicating copy to clipboard operation
google-auth-library-python-oauthlib copied to clipboard

Running run_local_server in Colab notebook doesn't redirect properly

Open chrissyast opened this issue 2 years ago • 3 comments

    if not creds or not creds.valid:
        if creds and creds.expired and creds.refresh_token:
            creds.refresh(Request())
        else:
            flow = InstalledAppFlow.from_client_secrets_file(
                'credentials.json', SCOPES)
            creds = flow.run_local_server(port=0)

Trying to run this in a Colab file prints a URL that I need to go to authorise the app. On doing so I'm redirected to http://localhost:58787/?state=blah which can't be reached and the notebook remains listening for a response.

chrissyast avatar Apr 19 '23 17:04 chrissyast

Can you trying removing the port=0 param? Usually a port is auto assigned I believe.

sai-sunder-s avatar Jul 18 '23 20:07 sai-sunder-s

@sai-sunder-s After removing the port param, I get an error OSError: [Errno 98] Address already in use

chrissyast avatar Jul 21 '23 11:07 chrissyast

I think I understood the problem. Since you are using colab, you are using a browser I am assuming? So colab doesn't have the ability to listen to localhost. That is why it just listens for a response indefinitely I guess.

I have heard of people using pydata-google-auth for notebook scenarios.

sai-sunder-s avatar Jul 21 '23 19:07 sai-sunder-s