GoogleCloudPlatform / gcs-oauth2-boto-plugin

Auth plugin allowing use the use of OAuth 2.0 credentials for Google Cloud Storage in the Boto library.
Apache License 2.0
21 stars 38 forks source link

How to get this working? #36

Open gilblau opened 6 years ago

gilblau commented 6 years ago

Hi, Can you please assist???? I am trying to use this plugin using docker. For some reason I don't seem to be able to get my python code to authenticate with GCP. I keep getting the following error message:

Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.7/dist-packages/boto/storage_uri.py", line 569, in create_bucket conn = self.connect() File "/usr/local/lib/python2.7/dist-packages/boto/storage_uri.py", line 140, in connect **connection_args) File "/usr/local/lib/python2.7/dist-packages/boto/gs/connection.py", line 47, in init suppress_consec_slashes=suppress_consec_slashes) File "/usr/local/lib/python2.7/dist-packages/boto/s3/connection.py", line 194, in init validate_certs=validate_certs, profile_name=profile_name) File "/usr/local/lib/python2.7/dist-packages/boto/connection.py", line 569, in init host, config, self.provider, self._required_auth_capability()) File "/usr/local/lib/python2.7/dist-packages/boto/auth.py", line 1021, in get_auth_handler 'Check your credentials' % (len(names), str(names))) boto.exception.NoAuthHandlerFound: No handler was ready to authenticate. 3 handlers were checked. ['OAuth2Auth', 'OAuth2ServiceAccountAuth', 'HmacAuthV1Handler'] Check your credentials

Steps:

python import boto import gcs_oauth2_boto_plugin OAUTH2_CLIENT_ID = 'client_id' OAUTH2_CLIENT_SECRET = 'client_secret' gcs_oauth2_boto_plugin.SetFallbackClientIdAndSecret(OAUTH2_CLIENT_ID, OAUTH2_CLIENT_SECRET) project_id='project_id' //I have my project id header_values = {"x-goog-project-id": project_id} uri = boto.storage_uri('my-bucket', 'gs') uri.create_bucket()

kevinoid commented 5 years ago

I just encountered the same error:

boto.exception.NoAuthHandlerFound: No handler was ready to authenticate. 3 handlers were checked. ['OAuth2Auth', 'OAuth2ServiceAccountAuth', 'HmacAuthV1Handler'] Check your credentials

In my case the problem was that I had added client_id and client_secret to the [OAuth2] section of ~/.boto but had not run gsutil config which adds gs_oauth2_refresh_token to the [Credentials] section. After running gsutil config and granting access via the OAuth prompt the error was resolved for me.