Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

localhost refused to connect - pandas GBQ

While running python script using "pandas GBQ" that reads and write on Big Query, I am getting a URL to authenticate the application. But after authenticating, getting error "localhost refused to connect."

Kindly help

0 1 723
1 REPLY 1

The error "localhost refused to connect" when using pandas-gbq to read and write to BigQuery after authenticating indicates an issue with the local web server that the library uses for authentication. Possible reasons include:

  • A firewall or security software on your computer blocking the connection.
  • An issue with the pandas-gbq authentication process itself.

To troubleshoot this issue:

  1. Disable any firewall or security software temporarily to see if it resolves the issue.
  2. Use manual authentication: Instead of letting the library automatically open a browser, manually copy the authentication URL, open it in a browser, authenticate, and then paste the resulting code back into your script.
  3. Consider using a service account for authentication. This method uses a JSON key file and doesn't require browser-based authentication.

Additional tips:

  • Ensure you're using the latest version of pandas-gbq.
  • Refer to the pandas-gbq documentation for more troubleshooting tips and details.