Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #5219 > unrolled thread

Re: urllib2 request with binary file as payload

Started byMichiel Sikma <michiel@wedemandhtml.com>
First post2011-05-12 10:05 +0200
Last post2011-05-12 10:05 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: urllib2 request with binary file as payload Michiel Sikma <michiel@wedemandhtml.com> - 2011-05-12 10:05 +0200

#5219 — Re: urllib2 request with binary file as payload

FromMichiel Sikma <michiel@wedemandhtml.com>
Date2011-05-12 10:05 +0200
SubjectRe: urllib2 request with binary file as payload
Message-ID<mailman.1452.1305187574.9059.python-list@python.org>
>
> 2.6 is expecting a string, according to the above. No mention of file.
> Moreover it expects the data to be urlencoded. 2.7.1 docs say the same
> thing. Are you sure you have shown the code that worked with 2.6?
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Yes, in fact I simply tried passing the file to the Request class
without having checked the docs to see if I could even do that, but it
worked. I also send an unencoded XML string a little bit earlier on.
Maybe it no longer needs to be a urlencoded string as soon as you add
a Content-Type header.

Here's what happens when I put the HTTPHandler in debug mode and pass
a file in 2.6:

send: 'PUT /resumable/feeds/api/users/default/uploads?upload_id=[id]HTTP/1.1\r\nAccept-Encoding:
identity\r\nContent-Length: 898801\r\nHost:
uploads.gdata.youtube.com\r\nContent-Type:
application/octet-stream\r\nConnection: close\r\nUser-Agent:
Python-urllib/2.6\r\n\r\n'
send: <open file 'file.mp4', mode 'rb' at 0x1005db580>
sendIng a read()able

A little while later:

reply: 'HTTP/1.1 201 Created\r\n'
[...etc]

So it seems to work just fine, but 2.5 does indeed complain about this
being an incorrect use of Request.

Moreover, though I can't upgrade my Python from 2.5 I was able to
compile another alongside it (latest stable 2.7) and use that with my
code, and it worked just fine. Uploaded a 6GB file to Youtube this
way. :)

Michiel Sikma
We Demand HTML

http://wedemandhtml.com/
michiel@wedemandhtml.com

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web