【问题标题】:An error occurred (404) when calling the PutObject operation: Not Found调用 PutObject 操作时发生错误 (404):未找到
【发布时间】:2020-08-25 01:30:32
【问题描述】:

我想使用以下代码将文件上传到 s3 云:

session = boto3.session.Session()
s3_client = session.resource('s3',
                               endpoint_url=credentials.get('endpoint_url'),
                               aws_access_key_id=credentials.get('access_key'),
                               aws_secret_access_key=credentials.get('secret_key'),
                               )
bucket = s3_client.Bucket("test")
bucket.upload_file("req.txt", "req.txt")

我得到这个错误:

boto3.exceptions.S3UploadFailedError: Failed to upload req.txt to test/req.txt: An error occurred (404) when calling the PutObject operation: Not Found

另外,我正在使用此代码:

session = boto3.session.Session()
s3_client = session.client(service_name='s3',
                           endpoint_url=credentials.get('endpoint_url'),
                           aws_access_key_id=credentials.get('access_key'),
                           aws_secret_access_key=credentials.get('secret_key'),
                           )


def upload_file(filename, bucket_name, name_in_bucket):
    s3_client.upload_file(filename, bucket_name, name_in_bucket)


upload_file('req.txt', 'test_mmdaz', 'testfile.txt')

我得到同样的错误。 有什么想法:?

【问题讨论】:

  • 运行代码时,req.txt 是否存在于您的工作目录中?
  • 我认为您需要将访问权限和密钥放入会话创建中。不是在定义您的 s3 客户端时。 See Session Doc
  • @jordanm 是的!当然。
  • endpoint_url 传递什么?您通常不必指定。
  • 您使用的凭据是否用于存储桶所在的正确帐户?

标签: python amazon-s3 boto3


【解决方案1】:

根据@RobertoS 的评论,我的错是桶:test 不在我的 s3 云对象服务中。

【讨论】:

    猜你喜欢
    • 2022-11-08
    • 2017-12-07
    • 2018-03-20
    • 2020-09-14
    • 1970-01-01
    • 2018-07-12
    • 2018-12-09
    • 2020-04-02
    • 1970-01-01
    相关资源
    最近更新 更多