Google 云 Python raspbian
Google Cloud Python on raspbian
我想使用我的 rasbperrypi:拍照并将照片发送到 firebase 存储。
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')
但是我有这个错误:
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
不过,我安装了google云服务/
> 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-核心,google-云核心,google-可恢复媒体
google.cloud 系统需要一些凭据。这可以是系统帐户或 OAuth。最简单的解决方案是创建一个包含您的帐户凭据的文件(A JSON blob)并设置环境变量 GOOGLE_APPLICATION_CREDENTIALS 以包含该文件的路径。然后运行你的软件。
使用您的帐户打开 Google Cloud Console,找到您的帐户凭据的定义位置。我真的不知道那是哪里..
我想使用我的 rasbperrypi:拍照并将照片发送到 firebase 存储。
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')
但是我有这个错误:
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
不过,我安装了google云服务/
> 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-核心,google-云核心,google-可恢复媒体
google.cloud 系统需要一些凭据。这可以是系统帐户或 OAuth。最简单的解决方案是创建一个包含您的帐户凭据的文件(A JSON blob)并设置环境变量 GOOGLE_APPLICATION_CREDENTIALS 以包含该文件的路径。然后运行你的软件。
使用您的帐户打开 Google Cloud Console,找到您的帐户凭据的定义位置。我真的不知道那是哪里..