为什么在使用boto上传文件时会得到400?

时间:2014-11-07 01:32:27

标签: python amazon-web-services amazon-s3 boto

我尝试将文件上传到boto

import io

from boto.s3 import connection
from boto.s3 import key

conn = connection.S3Connection()
bucket = conn.get_bucket('my-bucket')

my_key = key.Key(bucket, 'asdf')

d = b'this is a test....\n' * 512000
f = io.BytesIO(d)

my_key.send_file(f, size=4*1024)

然而,这导致:

boto.exception.S3ResponseError: S3ResponseError: 400 Bad Request
<?xml version="1.0" encoding="UTF-8"?><Error><Code>BadRequest</Code><Message>An error occurred when parsing the HTTP request.</Message><RequestId>[hex request ID]</RequestId><HostId>[giant piece of base64]</HostId></Error>

为什么此请求失败?

(注意:我在这里使用send_file的全部原因是因为open显然只支持阅读......)

1 个答案:

答案 0 :(得分:7)

对于它的价值,将send_file()替换为set_contents_from_file()为我工作(我有同样的错误)。