簡體   English   中英

我正在嘗試使用python從S3存儲桶中刪除文件,但無法刪除該文件

[英]I am trying to delete file from S3 bucket using python but I am not able to delete the file

>>> import boto
>>> s3 = boto.connect_s3('<access_key>', '<secret_key>')
>>> bucket = s3.lookup('donebox-static')
>>> key = bucket.new_key('testkey')
>>> key.set_contents_from_string('This is a test')
>>> key.exists()
>>> key.delete()

在刪除時,出現以下錯誤。 我正在使用Linux機器,但可以從Windows機器中刪除文件。 錯誤是:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/boto-2.48.0-py2.7.egg/boto/s3/key.py", line 558, in delete
    headers=headers)
  File "/usr/lib/python2.7/site-packages/boto-2.48.0-py2.7.egg/boto/s3/bucket.py", line 762, in delete_key
    query_args_l=None)
  File "/usr/lib/python2.7/site-packages/boto-2.48.0-py2.7.egg/boto/s3/bucket.py", line 781, in _delete_key_internal
    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>6CF28CE4F8227FAE</RequestId><HostId>mrS5DIDHvXgweWSlwmQYVE0H05jsnepXd+3PiMqHcjXhWPkfo8ibeWA9rBcm7fKkdAO2f/fUTjo=</HostId></Error

>

您的代碼非常好。 (我在自己的存儲桶上進行了測試,效果很好。)

錯誤消息是Access Denied 這意味着與您的AWS憑證關聯的實體(很可能是您的IAM用戶)不允許刪除該對象。 或者,很可能是該存儲桶中的任何對象。

檢查事項:

  • 查看您的IAM用戶 (或與您使用的憑據關聯的任何實體)上的策略
  • 查看donebox-static存儲桶上的donebox-static 桶策略

檢查這兩個策略,以確定為什么不允許刪除對象。 請記住-默認情況下,您不允許執行任何操作,因此您正在尋找確實授予您DeleteObject權限的策略。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM