Uploading an image using PUT

N

noelob

Hi All,

Let me start by saying that's I'm relatively new to Python, so please
be gentle!

I need to up upload a file to a Tomcat web app using httplib. The web
app requires the following:
Files need to be split into 100kb (102400b) and each file segment
loaded using the PUT request. It is also a requirement that the
following headers be sent:

For simplicity I've used an image (jpg) smaller than 100kb, so it
doesn't need to be chunked

headers = {
"Accept": "text/xml",
"Authorization": "testAuthHeader",
"Content-Length": 50172,
"Content-Range": "bytes 0-50172/50172",
"Content-Type": "image/jpeg",
"If-Match": "1",
"User-Agent": "(en-IE; Grinder)",
}

I make the following connection:

conn = httplib.HTTPConnection(url)
conn.request(method, uriStr, body, additionalHeaders)

where:
method = PUT
uriStr is the web app specific URI
body is the raw data (bytes) from the jpg image
additionalHeaders are the headers above

For some reason I keep getting a Status 400 error from the web server.
Is it possible to PUT (or POST?) data in this fashion using httplib?

Many thanks for your help
Noelob
 
N

noelob

Hi All,
I finally figured it out, thanks to Wireshark! I was adding my own
"Content-Length: 50173" header to the request, but httplib appears to
add its own header (also "Content-Length: 50173") which must have been
causing a conflict and making the sever return "HTTP/1.1 400 Bad
Request\r\n". As soon as I removed my own Content-Length header, it
worked!

Regards,
Noel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,096
Latest member
ThurmanCre

Latest Threads

Top