Google Cloud python project has localhost error

Viewed 435

I've been following the instructions for this guide: https://developers.google.com/gmail/api/quickstart/python

to run a basic program which reads a Gmail inbox.

Basically, the program opens up a new window asking you to login with your gmail account - once that is done, it gives the information back to the program which should print results on the google cloud shell terminal.

Whenever I login with the correct google account, the page shows "localhost refused to connect". For this reason, the rest of the program cannot continue, so the google cloud shell is stuck waiting for the login to occur. Would anyone have any ideas on why this localhost error is happening? Thanks in advance.

1 Answers

Solution

Run the code from your desktop.

The OAuth Flow that you are using requires a web browser. This means the webserver process must be running on your system.
You are trying to run code in Cloud Shell. And it does not have one. If you look at the source code run_local_server() starts a webserver. The server is running on the wrong system.

There are methods to create a public webserver (not using localhost). Then the issue becomes how to start the webserver on Cloud Shell. Except for experimenting you are using the wrong services (Cloud Shell).

Related