【问题标题】:s3 connection to 'folder' via botos3通过boto连接到“文件夹”
【发布时间】:2013-07-06 09:51:36
【问题描述】:

我正在尝试使用 boto 和 python 将文件上传到特定位置。我正在使用一些东西来达到这种效果:

from boto.s3.connection import S3Connection
from boto.s3.key import Key


conn = S3Connection(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
bucket = conn.get_bucket('the_bucket_name')
for key in bucket: 
    print key.name

这就是诀窍。我已将凭据配置到存储桶中的“文件夹”。根据这个 - Amazon S3 boto - how to create a folder? 我知道 s3 中实际上没有文件夹,而是像“foo/bar/my_key.txt”这样的键。当我尝试执行 get_bucket() 我得到 ​​p>

boto.exception.S3ResponseError: S3ResponseError: 403 Forbidden

因为我实际上没有基本存储桶的凭据,而是存储桶密钥的子集。 my_bucket/the_area_I_have_permission/*

有谁知道我如何在连接步骤中通过我可以访问的存储桶中的特定“区域”?还是我可以用来访问my_bucket/the_area_I_have_permission/* 的替代方法?

【问题讨论】:

    标签: python amazon-s3 boto


    【解决方案1】:

    发现问题。 RequestTimeTooSkewed Error using PHP S3 Class

    问题是我的虚拟机日期已关闭,亚马逊使用该日期来验证请求。 1+ 到@bdonlan。

    【讨论】:

      【解决方案2】:

      这有帮助吗:

      bucket = conn.get_bucket('the_bucket_name',validate=False)
      
      key = bucket.get_key("ur_key_name")
      if key is not None:
          print  key.get_contents_as_string()
      
      keys = bucket.list(prefix='the_area_I_have_permission')
      for key in keys:
          print key.name
      

      【讨论】:

      • 感谢您的回复。没有。 got TypeError: get_key() got an unexpected keyword argument 'prefix' for the first and boto.exception.S3ResponseError: S3ResponseError: 403 Forbidden for the second.
      • 哦,混合了两个不同的 API 调用。这个应该是电话。关于 403,您是否可以使用其他一些 clinet(可能是 Firefox 的 UI 或 S3Explorer 插件)使用这些 secretid/keys 访问存储桶?
      • 该死。我仍然得到第一个403。我正在尝试连接“bucket-name”,然后我将路径传递给我试图访问的文件,即:“/some/path/file.json”。那是对的吗?我试过带和不带前导斜线。
      • 至于 403,是的。我与 s3uploader 连接得很好,但是如果我尝试在任何地方导航,但我已经为其配置了凭据的特定文件夹,我会收到错误
      猜你喜欢
      • 1970-01-01
      • 2010-12-28
      • 2012-07-10
      • 2020-02-26
      • 1970-01-01
      • 1970-01-01
      • 2014-12-12
      • 1970-01-01
      • 2015-03-22
      相关资源
      最近更新 更多