我在Linux上使用Python2.7.9,在Google-Cloud Server SDK上使用谷歌的example。我的目标是上传一张图片到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'
代码:
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')
如何解决呢?
发布于 2018-12-12 23:02:20
要使其工作,只需编写zebraBlob = bucket.blob('testimg.jpg')
而不是zebraBlob = bucket.get_blob('testimg.jpg')
发布于 2018-12-02 10:24:17
遇到了同样的问题,只能通过从谷歌云控制台first (导航到您的存储桶并单击"Upload “)上传另一个图像来解决它。
一旦它被制作好了,它看起来工作得很好,并上传了新的图像,替换了另一个。
ps您可以在控制台上重命名镜像,如this
如果我知道如何在不做这个的情况下创建一个新文件,我将更新这篇文章,如果其他人已经知道了,请随时收件箱我来更新它:)
https://stackoverflow.com/questions/51439904
复制