Search code examples
pythonfirebasegoogle-cloud-storageraspbian

Google Cloud Python on raspbian


I want to use my rasbperrypi : take a photo and send the photo to firebase storage.

from google.cloud import storage
camera = PiCamera()
client = storage.Client()
bucket = client.get_bucket('gs://plante.appspot.com')


camera.start_preview()
sleep(5)
camera.capture('/home/pi/Desktop/culture/image.jpg')
camera.stop_preview()
sleep(5)

cultureBlob = bucket.get_blob('culture.jpg')
cultureBlob.upload_from_filename(filename='/home/pi/Desktop/culture/image.jpg')

But i have this error :

pi@raspberrypi:~ $ python test.py
Traceback (most recent call last):
  File "test.py", line 31, in <module>
    client = storage.Client()
  File "/home/pi/.local/lib/python2.7/site-packages/google/cloud/storage/client.py", line 71, in __init__
    _http=_http)
  File "/home/pi/.local/lib/python2.7/site-packages/google/cloud/client.py", line 215, in __init__
    _ClientProjectMixin.__init__(self, project=project)
  File "/home/pi/.local/lib/python2.7/site-packages/google/cloud/client.py", line 169, in __init__
    project = self._determine_default(project)
  File "/home/pi/.local/lib/python2.7/site-packages/google/cloud/client.py", line 182, in _determine_default
    return _determine_default_project(project)
  File "/home/pi/.local/lib/python2.7/site-packages/google/cloud/_helpers.py", line 179, in _determine_default_project
    _, project = google.auth.default()
  File "/home/pi/.local/lib/python2.7/site-packages/google/auth/_default.py", line 306, in default
    raise exceptions.DefaultCredentialsError(_HELP_MESSAGE)
google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS or explicitly create credentials and re-run the application. For more information, please see https://cloud.google.com/docs/authentication/getting-started

however, I have installed google cloud services /

> sudo pip install google-cloud-storage

pi@raspberrypi:~ $ gcloud version

Google Cloud SDK 225.0.0
alpha 2018.11.09
beta 2018.11.09
bq 2.0.37
core 2018.11.09
gsutil 4.34
kubectl 2018.11.09
pi@raspberrypi:~ $ pip show google-cloud-storage
Name: google-cloud-storage
Version: 1.13.0
Summary: Google Cloud Storage API client library
Home-page: https://github.com/GoogleCloudPlatform/google-cloud-python
Author: Google LLC
Author-email: googleapis-packages@google.com
License: Apache 2.0
Location: /home/pi/.local/lib/python2.7/site-packages
Requires: google

-api-core, google-cloud-core, google-resumable-media


Solution

  • The google.cloud system requires some credentials. This can be either a system account or OAuth. The simplest solution is to create a file containing your account credentials (A JSON blob) and set the environment variable GOOGLE_APPLICATION_CREDENTIALS to contain the path to that file. Then run your software.

    Open the Google Cloud Console using your account and find where your account credentials are defined. I dont actually know where that is..