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
Scripts started with CGIHTTPServer: missing cgi environment #41423
Comments
With Python 2.4 only (2.3 works fine). Tested on In run_cgi, sys.environ is updated with cgi variables The attached patch fixes this using the subprocess module. It fixes also (I think) bug 1088039 Patch note: the subprocess test (have_subprocess) is Diff follows, complete script attached. --- C:\apps\Python24\Lib\CGIHTTPServer-old.py Mon Aug
30 09:38:16 2004
+++ C:\apps\Python24\Lib\CGIHTTPServer.py Tue Jan 10
19:45:09 2005
@@ -234,18 +234,16 @@
elif self.have_popen2 or self.have_popen3:
# Windows -- use popen2 or popen3 to
create a subprocess
+ import subprocess
import shutil
- if self.have_popen3:
- popenx = os.popen3
- else:
- popenx = os.popen2
- cmdline = scriptfile
+
+ cmdline = '"%s"' % scriptfile
if self.is_python(scriptfile):
interp = sys.executable
if interp.lower().endswith("w.exe"):
# On Windows, use python.exe, not
pythonw.exe
interp = interp[:-5] + interp[-4:]
- cmdline = "%s -u %s" % (interp, cmdline)
+ cmdline = '"%s" -u %s' % (interp, cmdline)
if '=' not in query and '"' not in query:
cmdline = '%s "%s"' % (cmdline, query)
self.log_message("command: %s", cmdline)
@@ -253,11 +251,11 @@
nbytes = int(length)
except (TypeError, ValueError):
nbytes = 0
- files = popenx(cmdline, 'b')
- fi = files[0]
- fo = files[1]
- if self.have_popen3:
- fe = files[2]
+
+ p = subprocess.Popen(cmdline,
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
+
stderr=subprocess.PIPE, env=os.environ)
+ (fi, fo, fe) = (p.stdin, p.stdout, p.stderr)
+
if self.command.lower() == "post" and
nbytes > 0:
data = self.rfile.read(nbytes)
fi.write(data)
@@ -267,16 +265,16 @@
break
fi.close()
shutil.copyfileobj(fo, self.wfile)
- if self.have_popen3:
- errors = fe.read()
- fe.close()
- if errors:
- self.log_error('%s', errors)
+ errors = fe.read()
+ fe.close()
+ if errors:
+ self.log_error('%s', errors)
sts = fo.close()
if sts:
self.log_error("CGI script exit status
%#x", sts)
else:
self.log_message("CGI script exited OK")
+ del p
else:
# Other O.S. -- execute script in this process |
Logged In: YES Please have a look at bpo-1110478. The cause is in os.py. |
Logged In: YES As juneaftn says, this was caused by bpo-1110478, and is fixed in os.py 1.85 |
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: