关于这个问题还有一些其他问题:
boto.exception.S3ResponseError: S3ResponseError: 403 Forbidden
S3ResponseError: S3ResponseError: 403 Forbidden
S3ResponseError: 403 Forbidden using boto
Python: Amazon S3 cannot get the bucket: says 403 Forbidden
然而,似乎我可能遇到了不同的问题(例如,时钟偏差不是问题,我已经尝试设置validate=False
,我相信我有正确的密钥和密钥,因为尝试伪造密钥或秘密密钥给我不同的错误)。这是我的剧本:
import boto
import sys
from boto.s3.key import Key
BUCKET_NAME = sys.argv[1]
AWS_ACCESS_KEY_ID = sys.argv[2]
AWS_SECRET_ACCESS_KEY = sys.argv[3]
conn = boto.connect_s3(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
bucket = conn.get_bucket(BUCKET_NAME, validate=False)
k = Key(bucket)
k.key = 'barbaz'
k.set_contents_from_filename('/tmp/barbaz.txt')
结果:
Traceback (most recent call last):
File "/home/jonderry/sdmain/src/scripts/jenkins/upload_to_s3.py", line 16, in <module>
k.set_contents_from_filename('/tmp/barbaz.txt')
File "/usr/local/lib/python2.7/dist-packages/boto/s3/key.py", line 1360, in set_contents_from_filename
encrypt_key=encrypt_key)
File "/usr/local/lib/python2.7/dist-packages/boto/s3/key.py", line 1291, in set_contents_from_file
chunked_transfer=chunked_transfer, size=size)
File "/usr/local/lib/python2.7/dist-packages/boto/s3/key.py", line 748, in send_file
chunked_transfer=chunked_transfer, size=size)
File "/usr/local/lib/python2.7/dist-packages/boto/s3/key.py", line 949, in _send_file_internal
query_args=query_args
File "/usr/local/lib/python2.7/dist-packages/boto/s3/connection.py", line 664, in make_request
retry_handler=retry_handler
File "/usr/local/lib/python2.7/dist-packages/boto/connection.py", line 1068, in make_request
retry_handler=retry_handler)
File "/usr/local/lib/python2.7/dist-packages/boto/connection.py", line 939, in _mexe
request.body, request.headers)
File "/usr/local/lib/python2.7/dist-packages/boto/s3/key.py", line 882, 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>***someRequestId***</RequestId><HostId>***someHostId</HostId></Error>
任何想法是什么问题,或如何进一步诊断?
答案 0 :(得分:29)
如果机器的时间设置不正确,也会发生这种情况
答案 1 :(得分:2)
看起来你没有权利在这个桶上写字。什么是存储桶策略?你能确定这个IAM用户可以放这个桶吗?
答案 2 :(得分:0)
我在尝试validate=False
和ntpdate
以及给予&#34; Authenticated Users&#34;在AWS上上传/删除的权限。我的解决方案可能很少见,但万一其他人这样做了:
我开始使用我的环境中的凭据运行我的Django应用程序以获取我的存储桶&#39; xyz&#39;。然后我更改了凭据以上传到我朋友的桶#abc&#39;。这些凭证之间存在不匹配,所以我需要做的就是重新启动gunicorn。