Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #5219
| References | <BANLkTikW_Yq9XL=rBxnsOAYjSjXXVk9MUA@mail.gmail.com> <2fa89ca32d0796866e0fe4121371b882.squirrel@webmail.lexicon.net> |
|---|---|
| From | Michiel Sikma <michiel@wedemandhtml.com> |
| Date | 2011-05-12 10:05 +0200 |
| Subject | Re: urllib2 request with binary file as payload |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1452.1305187574.9059.python-list@python.org> (permalink) |
> > 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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: urllib2 request with binary file as payload Michiel Sikma <michiel@wedemandhtml.com> - 2011-05-12 10:05 +0200
csiph-web