Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I get a 400 when uploading a file with boto?

I'm attempting to upload a file to 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)

However, this results in:

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>

Why is this request failing?

(note: the whole reason I'm using send_file here is because open apparently only supports reading…)

like image 443
Thanatos Avatar asked Nov 07 '14 01:11

Thanatos


1 Answers

For what it's worth, replacing send_file() with set_contents_from_file() worked for me (I had the same error).

like image 153
Eric O Lebigot Avatar answered Oct 14 '22 14:10

Eric O Lebigot