[Twisted-Python] Doing HTTP file uploads (multipart forms)

Laurens Van Houtven _ at lvh.cc
Fri Jul 6 05:32:19 EDT 2012


As an extra reference, see the behavior Firefox has when approaching the sample server (with some value for the sample field and the Axiom README as the file):

-------------- next part --------------
A non-text attachment was scrubbed...
Name: ff-behavior.pcap
Type: application/octet-stream
Size: 3769 bytes
Desc: not available
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20120706/8373a110/attachment.obj 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: ff-behavior.txt
Url: http://twistedmatrix.com/pipermail/twisted-python/attachments/20120706/8373a110/attachment.txt 
-------------- next part --------------

cheers
lvh



On 06 Jul 2012, at 10:47, Laurens Van Houtven wrote:

> Hi,
> 
> I have some code that takes file uploads from browsers. I'm trying to write a test for it, so now I need to get Twisted to do file uploads like browsers do. I think my code (not test code) essentially works, by manually trying it with a browser. I can't get the functional test part to work.
> 
> I have reduced the problem to what I think is a SSCCE. render_POST drops into a debugger to easily inspect the received request.
> 
> Here's the code: https://gist.github.com/3058974
> 
> When debugging this with wireshark I found an obvious culprit: there's some random junk in front of it (3 ASCII hex digits and a CRLF) and some junk at the end (CRLF and an ASCII "0", although I'm not sure if that CRLF is junk). Wireshark reports some broken TCP packets (PCAP attached). I have no idea why that happens. Packets were captured with:
> 
>    tcpdump -i lo0 -nn -s0 -w sample.pcap port 8080
> 
> and analyzed with a recent version of Wireshark (1.6.2, SVN rev 38931). The analyzed TCP stream is also attached.
> 
> <tcpdata.txt><test.pcap>
> 
> If I look at the request in the debugger (request_POST *DOES* get called…):
> 
> - it has an empty request.args, instead of having the expected keys "a", "b", "f"
> - request.content.getvalue() has the data you see in tcpdata.txt: it starts with "'1e7\r\n------------" even though I obviously would like it to start with just the dashes
> 
> cheers
> lvh
> 
> 
> 



More information about the Twisted-Python mailing list