can not authenticate with gcs in python
Asked Answered
R

3

6

I am following the example in https://developers.google.com/storage/docs/gspythonlibrary#credentials

I created client/secret pair by choosing in the dev. console "create new client id", "installed application", "other".

I have the following code in my python script:

import boto
from gcs_oauth2_boto_plugin.oauth2_helper import SetFallbackClientIdAndSecret
CLIENT_ID = 'my_client_id'
CLIENT_SECRET = 'xxxfoo'
SetFallbackClientIdAndSecret(CLIENT_ID, CLIENT_SECRET)

uri = boto.storage_uri('foobartest2014', 'gs')
header_values = {"x-goog-project-id": proj_id}
uri.create_bucket(headers=header_values)

and it fails with the following error:

   File "/usr/local/lib/python2.7/dist-packages/boto/storage_uri.py", line 555, 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 190, in __init__
      validate_certs=validate_certs, profile_name=profile_name)
    File "/usr/local/lib/python2.7/dist-packages/boto/connection.py", line 572, in __init__
      host, config, self.provider, self._required_auth_capability())
    File "/usr/local/lib/python2.7/dist-packages/boto/auth.py", line 883, 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
Reactance answered 29/6, 2014 at 14:10 Comment(1)
Have you thought about trying gcloud-python (github.com/GoogleCloudPlatform/gcloud-python) ? Might be easier than using botoHarder
G
2

You need to provide a client/secret pair in a .boto file, and then run gsutil config.

It will create a refresh token, and then should work!

For more info, see https://developers.google.com/storage/docs/gspythonlibrary#credentials

Goy answered 9/11, 2015 at 19:3 Comment(2)
Why do we need to specify the client_id and client_secret in both the .boto file and the source code?Anergy
See @griffin2000's answer, boto is obsolete and will get you nowhere with Google.Falter
N
5

I have been struggling with this for the last couple of days, turns out the boto stuff, and that gspythonlibrary are all totally obsolete.

The latest example code showing how to use/authenticate Google Cloud Storage is here: https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/storage/api

Nazar answered 9/12, 2016 at 2:47 Comment(3)
why you think it's obsoleted? it still appears here: cloud.google.com/storage/docs/xml-api/gspythonlibraryReactance
Yeah that doc is way out of date. If you try and follow those instructions with a recent version of gcloud it will fail completely. The whole boto system, described there, is longer supported (or at least strongly discouraged)Nazar
Thanks @griffin2000, I wasted hours looking at their docs and opening support tickets until I found your comment. I'm up and running 2 minutes later... I can't believe they are still hosting BAD/WRONG docs. No docs are better than wrong docs.Falter
G
2

You need to provide a client/secret pair in a .boto file, and then run gsutil config.

It will create a refresh token, and then should work!

For more info, see https://developers.google.com/storage/docs/gspythonlibrary#credentials

Goy answered 9/11, 2015 at 19:3 Comment(2)
Why do we need to specify the client_id and client_secret in both the .boto file and the source code?Anergy
See @griffin2000's answer, boto is obsolete and will get you nowhere with Google.Falter
F
0

U can also make console application for gsutil commands authentication and gsutil cp, rm, gsutil config -a pass through console application to cloud SDK then execute

Forewarn answered 28/4, 2018 at 7:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.