AttributeError 'NoneType' 对象没有属性 'upload_from_filename'

Jso*_*son 2 python firebase google-cloud-platform

我在 Linux 上使用 Python 2.7.9,我在 Google-Cloud Server SDK 上遵循 Google 的示例。我的目标是将图像上传到 Google Cloud Platform,但出现以下错误。

File "/home/pi/test.py", line 15, in <module>
  zebraBlob.upload_from_filename(filename='/home/pi/Pictures/testimg.jpg')
AttributeError: 'NoneType' object has no attribute
  'upload_from_filename'
Run Code Online (Sandbox Code Playgroud)

代码:

from firebase import firebase
from google.cloud import storage
import os

firebase = firebase.FirebaseApplication('https://motion-detector-234.firebaseio.com', None)
storage_client = storage.Client.from_service_account_json('Motion Detector-8gf5445fgeeea.json')

bucket = storage_client.get_bucket('motion-detector-210fds717.appspot.com')
print ('bucket', bucket) // output: bucket, motion-detector-210717.appspot.com

zebraBlob = bucket.get_blob('testimg.jpg')
print(zebraBlob) // output: None

zebraBlob.upload_from_filename(filename='/home/pi/Pictures/testimg.jpg')
Run Code Online (Sandbox Code Playgroud)

如何解决?

fen*_*ske 5

为了使它工作,你应该简单地写zebraBlob = bucket.blob('testimg.jpg')而不是zebraBlob = bucket.get_blob('testimg.jpg')