我想用我的雷斯伯里:拍张照片,然后把照片送到火柴仓库。
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-storagepi@raspberrypi:~ $ gcloud版本
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.09pi@raspberrypi:~ $ pip显示google-云存储
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-云-core,google-可恢复-媒体
发布于 2018-11-25 11:22:09
google.cloud系统需要一些凭据。可以是系统帐户,也可以是OAuth。最简单的解决方案是创建一个包含帐户凭据( JSON )的文件,并将环境变量GOOGLE_APPLICATION_CREDENTIALS设置为包含该文件的路径。那就运行你的软件。
使用您的帐户打开Google控制台,并找到您的帐户凭据定义的位置。我真的不知道那是在哪里。
https://stackoverflow.com/questions/53461447
复制相似问题