【发布时间】:2017-09-05 21:17:51
【问题描述】:
我正在尝试连接到 S3 存储桶(第 3 方是所有者,因此我无法通过 AWS 控制台访问)。使用 CyberDuck,我可以毫无问题地连接和上传文件。但是我已经尝试了几个库来连接到存储桶,所有这些库都返回 403 禁止。我在这里发帖希望有人能发现我做错了什么。
def send_to_s3(file_name):
csv = open("/tmp/" + file_name, 'rb')
conn = tinys3.Connection("SECRET",
"SECRET",
tls=True,
endpoint="s3.amazonaws.com")
conn.upload("MDA-Data-Ingest/input/" + file_name, csv, bucket="gsext-69qlakrroehhgr0f47bhffnwct")
def send_via_ftp(file_name):
cnopts = pysftp.CnOpts()
cnopts.hostkeys = None
srv = pysftp.Connection(host="gsext-69qlakrroehhgr0f47bhffnwct.s3.amazonaws.com",
username="SECRET",
password="SECRET",
port=443,
cnopts=cnopts)
with srv.cd('\MDA-Data-Ingest\input'):
srv.put('\\tmp\\'+file_name)
# Closes the connection
srv.close()
def send_via_boto(file_name):
access_key = 'SECRET'
secret_key = 'SECRET'
conn = boto.connect_s3(
aws_access_key_id=access_key,
aws_secret_access_key=secret_key,
host='s3.amazonaws.com',
# is_secure=False, # uncomment if you are not using ssl
calling_format=boto.s3.connection.OrdinaryCallingFormat(),
)
所有这些函数都返回一个 403 禁止,如下所示:
HTTPError: 403 Client Error: Forbidden for url: https://gsext-69qlakrroehhgr0f47bhffnwct.s3.amazonaws.com/MDA-Data-Ingest/input/accounts.csv
但是,当我使用 CyberDuck 时,我可以正常连接:
【问题讨论】:
-
编辑:在某一时刻,通过 ftp 发送显示 403(我不记得它在发送 403 时的样子),因为它位于它吐出的错误之上:SSHException:错误读取 SSH 协议横幅[Errno 54] 对等方重置连接
标签: python amazon-web-services amazon-s3