Ich bin eine wirklich harte Zeit Anwendung Standard Credientials /OAuth2.0 bekommen, was mit in mein Programm zu arbeiten ...Google Cloud Storage Access Client API
Hintergrund:
ich eine Sensoreinrichtung haben das sammelt Bilder, und ich möchte diese Bilder in Google Cloud-Speicher in einem Eimer speichern. Idealerweise wird der Code nur auf Knopfdruck ausgeführt, sodass die Autorisierung beim Ausführen des Programms erfolgen muss.
Vom Lesen und die Dokumentation Re-Lektüre, das ist, was ich bisher habe gehen:
from oauth2client.client import GoogleCredentials
from google.cloud import storage
import google.auth
import os
# Establish cloud credientials with a locally
# stored service account key
home_path = os.path.expanduser('~') + "/Project/"
auth_file = "<service account access key file>.json"
auth_file_path = home_path + auth_file
# I'm trying two different ways to verify my credentials..
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = auth_file_path
credentials, project_id = google.auth.default()
# Get storage bucket for image files
storage = storage.Client(project_id)
bucket = storage.lookup_bucket('bucket0000')
Als Ergebnis erhalte ich einen Fehler Zurückverfolgungs:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 110, in <module>
File "/Users/joshua/anaconda/lib/python3.5/site-packages/google/cloud/storage/client.py", line 193, in lookup_bucket
return self.get_bucket(bucket_name)
File "/Users/joshua/anaconda/lib/python3.5/site-packages/google/cloud/storage/client.py", line 173, in get_bucket
bucket.reload(client=self)
File "/Users/joshua/anaconda/lib/python3.5/site-packages/google/cloud/storage/_helpers.py", line 99, in reload
_target_object=self)
File "/Users/joshua/anaconda/lib/python3.5/site-packages/google/cloud/_http.py", line 303, in api_request
error_info=method + ' ' + url)
google.cloud.exceptions.Forbidden: 403 Caller does not have storage.buckets.get access to bucket bucket0000. (GET https://www.googleapis.com/storage/v1/b/bucket0000?projection=noAcl)
wo es scheint, dass ich immer noch als anonymer Benutzer betrachtet werde (über den Link googleapis.com im Traceback)
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Anonymous users does not have storage.buckets.get access to bucket bucket0000.",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Anonymous users does not have storage.buckets.get access to bucket bucket0000."
}
}
wieder versucht, diesmal mit google.auth, habe ich ein Credential-Variable, und beobachtet, was druckt es scheint gültig: <oauth2client.service_account._JWTAccessCredentials object at 0x107df0358>
Ich habe versucht, diese Anmeldeinformationen Variable in storage.Client setzen(), aber das scheint nicht arbeiten.
# Get storage bucket for image files
storage = storage.Client(project_id, credentials=credentials)
bucket = storage.lookup_bucket('bucket0000')
>>> Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 6, in <module>
File "/Users/joshua/anaconda/lib/python3.5/site-packages/google/cloud/storage/client.py", line 59, in __init__
_http=_http)
File "/Users/joshua/anaconda/lib/python3.5/site-packages/google/cloud/client.py", line 212, in __init__
Client.__init__(self, credentials=credentials, _http=_http)
File "/Users/joshua/anaconda/lib/python3.5/site-packages/google/cloud/client.py", line 126, in __init__
raise ValueError(_GOOGLE_AUTH_CREDENTIALS_HELP)
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
Natürlich ist diese Zurückverfolgungs leitet mich auf die Seite google-cloud-python.readthedocs.io ... die es nicht gibt ...
irgendeine Weise API-Aufrufe in den Cloud zu bekommen Storage funktioniert ohne die Konsole/Web einloggen?
sehr geschätzt!
Verwenden Sie Google App Engine wirklich? Es ist nicht klar aus dem Code. Die Cloud Storage-Authentifizierung für App Engine und andere Apps ist anders. Daher ist es wichtig, dass Sie sich darüber im Klaren sind. – snakecharmerb