【问题标题】:S3 object has no attribute BucketS3 对象没有属性 Bucket
【发布时间】:2021-12-07 01:56:13
【问题描述】:

我正在尝试运行这样的代码 sn-p:

s3_file_path = "testunzipping/sample.csv.gz"
s3 = boto3.client('s3')
lst = s3.list_objects(Bucket='testunzipping')['Contents']
firstbucket = s3.Bucket('testunzipping')

但我在最后一行收到一个错误:

"errorMessage": "'S3' object has no attribute 'Bucket'",

后来我像这样使用第一个桶:

firstbucket.upload_fileobj(destination_file_gz, s3_filename)

我做错了什么?我也尝试使用bucket 而不是Bucket

【问题讨论】:

标签: python amazon-web-services amazon-s3 boto attributeerror


【解决方案1】:

boto.clientboto.resource 之间有区别

.Bucket 只在后者上定义:

s3_resource = boto3.resource('s3')
bucket = s3.Bucket('name')

对比

s3_client = boto3.client('s3')
s3.list_objects(...)

【讨论】:

  • open函数呢? (s3.open(s3_file_path, mode="wb")) 它给了我一个 S3(客户端)和 s3_resource(资源)的错误
  • @x89 在 boto 中没有 s3.open 这样的东西。您确定要 open 一个 s3 对象而不是本地文件吗?
  • 啊,是的,你是对的 - 你能看看这里吗? stackoverflow.com/questions/69641719/…
猜你喜欢
  • 1970-01-01
  • 2021-08-06
  • 1970-01-01
  • 2020-11-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-01
相关资源
最近更新 更多