Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to authenticate Google Cloud Storage client in python

I'm trying the following code to access the Google Cloud storage:

client = storage.Client(credentials = GoogleCredentials.from_stream(<path-to-service-account-json>))

Throws this error:

ValueError: This library only supports credentials from google-auth-library-python. See https://google-cloud-python.readthedocs.io/en/latest/google-cloud-auth.html for help on authentication with this library.

I'm able to authenticate discovery.build service using the same credentials(obtained using GoogleCredentials.from_stream()), but for some reason storage.Client fails to use the provided credentials.

Please let me know if I'm missing something.

like image 859
Fayaz Ahmed Avatar asked Aug 12 '17 01:08

Fayaz Ahmed


People also ask

How do I authenticate with Google Cloud Storage?

API authenticationIn the OAuth 2.0 Playground, click Cloud Storage API v1, and then select an access level for your application ( full_control , read_only , or read_write ). Click Authorize APIs. Sign in to your Google account when prompted. In the dialogue that appears, click Allow.

How do I install Google Cloud Storage in Python?

Type "cmd" in the search bar and hit Enter to open the command line. What is this? Type “ pip install google-cloud-storage ” (without quotes) in the command line and hit Enter again. This installs google-cloud-storage for your default Python installation.


1 Answers

Got it to work with the following code:

storage_client = storage.Client.from_service_account_json(<path-to-service-account-json>)

Not sure why there are different way to authenticate the discovery API and the storage and other client APIs.

like image 81
Fayaz Ahmed Avatar answered Sep 24 '22 22:09

Fayaz Ahmed