【问题标题】:boto key.set_contents_from_string() fails with 403 (but aws s3 cp works)boto key.set_contents_from_string() 以 403 失败(但 aws s3 cp 有效)
【发布时间】:2016-09-23 16:03:19
【问题描述】:

当我尝试使用boto 上传文件时,它以403 Forbidden 失败,我想知道我错过了什么。

命令行aws s3 cp foobar s3://bucket-name/topdir/foobar 运行正常,文件已上传。

在 boto 中,我可以列出存储桶并检索文件内容。

对存储桶的 IAM 用户权限设置为 Put/Get/DeleteObject。我也尝试过其他方法,例如set_contents_from_file,但都失败了。 Python 2.6.8。

我要解决的问题是:从 ftp 读取文件并推送到 S3。喜欢:

k = boto.s3.key.Key(b)
k.name = 'new-name'
ftp_handle.retrbinary('remote-name', k.set_contents_from_string)

下面是我的 python 会话。感谢您的帮助。

$ python
>>> import boto
>>> conn = boto.connect_s3()
>>> b = conn.get_bucket("bucket-name")
>>> k = boto.s3.key.Key(b)
>>> k.name = "topdir/foobar"
>>> k.set_contents_from_string("hello, world")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib64/python2.6/site-packages/boto-2.32.1-py2.6.egg/boto/s3/key.py", line 1419, in set_contents_from_string
    encrypt_key=encrypt_key)
  File "/usr/local/lib64/python2.6/site-packages/boto-2.32.1-py2.6.egg/boto/s3/key.py", line 1286, in set_contents_from_file
    chunked_transfer=chunked_transfer, size=size)
  File "/usr/local/lib64/python2.6/site-packages/boto-2.32.1-py2.6.egg/boto/s3/key.py", line 746, in send_file
    chunked_transfer=chunked_transfer, size=size)
  File "/usr/local/lib64/python2.6/site-packages/boto-2.32.1-py2.6.egg/boto/s3/key.py", line 944, in _send_file_internal
    query_args=query_args
  File "/usr/local/lib64/python2.6/site-packages/boto-2.32.1-py2.6.egg/boto/s3/connection.py", line 664, in make_request
    retry_handler=retry_handler
  File "/usr/local/lib64/python2.6/site-packages/boto-2.32.1-py2.6.egg/boto/connection.py", line 1053, in make_request
    retry_handler=retry_handler)
  File "/usr/local/lib64/python2.6/site-packages/boto-2.32.1-py2.6.egg/boto/connection.py", line 923, in _mexe
    request.body, request.headers)
  File "/usr/local/lib64/python2.6/site-packages/boto-2.32.1-py2.6.egg/boto/s3/key.py", line 880, in sender
    response.status, response.reason, body)
boto.exception.S3ResponseError: S3ResponseError: 403 Forbidden
<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>AccessDenied</Code><Message>Access Denied</Message><RequestId>...</RequestId><HostId>...</HostId></Error>

我所遵循的手册与我拥有的 boto 版本(2.32 与 2.34)略有不同步:http://boto.readthedocs.org/en/latest/ref/s3.html 所以也许 boto 2.32 真的不支持。但这不应该产生 403,不是吗?

【问题讨论】:

    标签: amazon-s3 boto


    【解决方案1】:

    您可能想要使用 connect_to_region 而不是 s3connect。将文件上传到 s3 时我遇到了类似的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-03
      • 2022-08-16
      • 1970-01-01
      • 2018-03-04
      • 1970-01-01
      • 1970-01-01
      • 2018-03-29
      • 1970-01-01
      相关资源
      最近更新 更多