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.

POST / HTTP/1.1
Connection: close
Transfer-Encoding: chunked
Content-Length: 487
Content-Type: multipart/form-data; 
boundary=-----------------------------8980579581609230477785168766
Host: localhost:8080

1e7
-----------------------------8980579581609230477785168766
Content-Disposition: form-data; name=a

1

-----------------------------8980579581609230477785168766
Content-Disposition: form-data; name=b

2

-----------------------------8980579581609230477785168766
Content-Disposition: form-data; name=f; filename=img.jpeg
Content-Type: image/jpeg

xyzzy

-----------------------------8980579581609230477785168766
-----------------------------8980579581609230477785168766--

0

Attachment: test.pcap
Description: Binary data


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



_______________________________________________
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

Reply via email to