New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Windows] cgi handling of POSTed files is broken in Windows #52324
Comments
I am reluctant to post this because (a) I might have made some dumb mistake in my code, simple as it is, and (b) the problem might be well-known or even hopeless because the cgi module may not be WSGI compliant, but if this isn't going to be fixed then at least the problem should be described in the cgi module documentation. I run an HTTPServer with a CGIHTTPRequestHandler. The attached zip file contains: This is on OS X 10.5 with either Python3.1 or Python3.2 from the repository. |
This doesn't look like a documentation bug to me - handling of uploaded files via CGI *should* work, even if CGI is not the best way to do that. |
The example works for me if I make this change: --- Lib/cgi.py (revision 81862)
+++ Lib/cgi.py (working copy)
@@ -608,7 +608,7 @@
parser = email.parser.FeedParser()
# Create bogus content-type header for proper multipart parsing
parser.feed('Content-Type: %s; boundary=%s\r\n\r\n' % (self.type, ib))
- parser.feed(self.fp.read())
+ parser.feed(self.fp.read(self.length))
full_msg = parser.close()
# Get subparts
msgs = full_msg.get_payload() However this seems iffy to me because the content length presumably counts bytes whereas self.fp seems to be a text file, but since most HTTP clients don't close the connection, without some kind of boundary on the read() call it just hangs forever. Also someone pointed out to me offline that this change may be needed, separately (though I haven't confirmed this yet): --- Lib/cgi.py (revision 81862)
+++ Lib/cgi.py (working copy)
@@ -233,6 +233,7 @@
lines = []
while 1:
line = fp.readline()
+ line = line.decode()
if not line:
terminator = lastpart # End outer loop
break |
Could this be related to bpo-4953? |
There are 2 different problems :
The attached patch modifies http.server :
With this patch, the tests provided by Mitchell all work on my PC (Windows XP Pro SP3) |
cgi module is deprecated as per PEP 594 hence closing. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: