Skip to content
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

Closed
pacote mannequin opened this issue Jan 11, 2005 · 3 comments
Closed

Scripts started with CGIHTTPServer: missing cgi environment #41423

pacote mannequin opened this issue Jan 11, 2005 · 3 comments
Labels
stdlib Python modules in the Lib dir

Comments

@pacote
Copy link
Mannequin

pacote mannequin commented Jan 11, 2005

BPO 1100235
Nosy @loewis
Files
  • CGIHTTPServer.py: New version of CGIHTTPServer.py
  • 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:

    assignee = None
    closed_at = <Date 2005-01-29.13:34:38.000>
    created_at = <Date 2005-01-11.16:00:05.000>
    labels = ['library']
    title = 'Scripts started with CGIHTTPServer: missing cgi environment'
    updated_at = <Date 2005-01-29.13:34:38.000>
    user = 'https://bugs.python.org/pacote'

    bugs.python.org fields:

    activity = <Date 2005-01-29.13:34:38.000>
    actor = 'loewis'
    assignee = 'none'
    closed = True
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2005-01-11.16:00:05.000>
    creator = 'pacote'
    dependencies = []
    files = ['1556']
    hgrepos = []
    issue_num = 1100235
    keywords = []
    message_count = 3.0
    messages = ['23924', '23925', '23926']
    nosy_count = 3.0
    nosy_names = ['loewis', 'juneaftn', 'pacote']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue1100235'
    versions = ['Python 2.4']

    @pacote
    Copy link
    Mannequin Author

    pacote mannequin commented Jan 11, 2005

    With Python 2.4 only (2.3 works fine). Tested on
    Windows 2000.

    In run_cgi, sys.environ is updated with cgi variables
    (QUERY_STRING, etc.)
    but it seems that this environment is not passed to the
    child process.
    On Windows os.popen3 is used but something must have
    changed in that function that is causing this regression.

    The attached patch fixes this using the subprocess module.

    It fixes also (I think) bug 1088039
    ("directories/scripts with spaces in their name").
    Supports too Python installed in a directory with a
    space (e.g. "Program Files").

    Patch note: the subprocess test (have_subprocess) is
    kind of awkward: is there a better way to do this?

    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

    @pacote pacote mannequin closed this as completed Jan 11, 2005
    @pacote pacote mannequin added the stdlib Python modules in the Lib dir label Jan 11, 2005
    @pacote pacote mannequin closed this as completed Jan 11, 2005
    @pacote pacote mannequin added the stdlib Python modules in the Lib dir label Jan 11, 2005
    @juneaftn
    Copy link
    Mannequin

    juneaftn mannequin commented Jan 27, 2005

    Logged In: YES
    user_id=116941

    Please have a look at bpo-1110478. The cause is in os.py.

    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Jan 29, 2005

    Logged In: YES
    user_id=21627

    As juneaftn says, this was caused by bpo-1110478, and is fixed in

    os.py 1.85
    test_os.py 1.29
    NEWS 1.1235
    os.py 1.83.2.1
    NEWS 1.1193.2.17

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 9, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir
    Projects
    None yet
    Development

    No branches or pull requests

    0 participants