Cannot authenticate with gcs in python

I follow an example at https://developers.google.com/storage/docs/gspythonlibrary#credentials

I created a client / secret pair by selecting in dev. console "create a new client identifier", "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 does not work 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 
+6
source share
2 answers

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

It will create an update token, and then it should work!

See https://developers.google.com/storage/docs/gspythonlibrary#credentials for more information.

+2
source

I struggled with this for the last two days, it turns out boto stuff, and that gspythonlibrary is completely out of date.

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

+3
source

Source: https://habr.com/ru/post/971494/


All Articles