AttributeError: 'NoneType' object has no attribute 'set_acl'

AttributeError: 'NoneType' object has no attribute 'set_acl'

我正在尝试在存储桶中创建一个文件 public,但遇到此错误:

AttributeError: 'NoneType' 对象没有属性 'set_acl'

你看到代码有什么问题了吗?

def makeFilePublic(bucketName):
    s3 = boto.s3.connect_to_region('us-east-1') 
    bucket = s3.get_bucket(bucketName)
    key = bucket.lookup('uploadedfiles/part-00000')
    key.set_acl('public-read')

唯一可能发生的情况是调用 bucket.lookup 未能在此存储桶中找到指定的对象。在那种情况下,它将 return 一个 None。在继续调用 set_acl.

之前,您必须检查一下