Skip to content

cgitb.py should assume a binary stream for output #54688

Description

@vpython
mannequin
BPO 10479
Nosy @freddrake, @facundobatista, @orsenthil

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 = None
created_at = <Date 2010-11-21.05:37:14.091>
labels = ['3.10', 'type-bug', '3.8', '3.9', 'expert-unicode']
title = 'cgitb.py should assume a binary stream for output'
updated_at = <Date 2020-11-16.21:55:03.466>
user = 'https://bugs.python.org/vpython'

bugs.python.org fields:

activity = <Date 2020-11-16.21:55:03.466>
actor = 'iritkatriel'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Unicode']
creation = <Date 2010-11-21.05:37:14.091>
creator = 'v+python'
dependencies = []
files = []
hgrepos = []
issue_num = 10479
keywords = []
message_count = 2.0
messages = ['121865', '127574']
nosy_count = 4.0
nosy_names = ['fdrake', 'facundobatista', 'orsenthil', 'v+python']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue10479'
versions = ['Python 3.8', 'Python 3.9', 'Python 3.10']

Activity

  1. vpython commented on Nov 21, 2010

    vpythonmannequin
    MannequinAuthor

    The CGI interface is a binary stream, because it is pumped directly to/from the HTTP protocol, which is a binary stream.

    Hence, cgitb.py should produce binary output. Presently, it produces text output.

    When one sets stdout to a binary stream, and then cgitb intercepts an error, cgitb fails.

    Demonstration of problem:

    import sys
    import traceback
    sys.stdout = open("sob", "wb")  # WSGI sez data should be binary, so stdout should be binary???
    import cgitb
    sys.stdout.write(b"out")
    fhb = open("fhb", "wb")
    cgitb.enable()
    fhb.write("abcdef")  # try writing non-binary to binary file.  Expect an error, of course.
  2. vpython commented on Jan 31, 2011

    vpythonmannequin
    MannequinAuthor

    So since cgi.py was fixed to use the .buffer attribute of sys.stdout, that leaves sys.stdout itself as a character stream, and cgitb.py can successfully write to that.

    If cgitb.py never writes anything but ASCII, then maybe that should be documented, and this issue closed.

    If cgitb.py writes non-ASCII, then it should use an appropriate encoding for the web application, which isn't necessarily the default encoding on the system. Some user control over the appropriate encoding should be given, or it should be documented that the encoding of sys.stdout should be changed to an appropriate encoding, because that is where cgitb.py will write its character stream. Guidance on how to do that would be appropriate for the documentation also, as a CGI application may be the first one a programmer might write that can't just use the default encoding configured for the system.

  3. transferred this issue fromon Apr 10, 2022
  4. hugovk commented on Apr 11, 2022

    @hugovk
    Member

    I think we can close this old issue as the cgitb module is deprecated in 3.11 and set for removal in 3.13.

    See PEP 594 – Removing dead batteries from the standard library, #91217 and #32410.

  5. AlexWaygood commented on Apr 12, 2022

    @AlexWaygood
    Member

    I think we can close this old issue as the cgitb module is deprecated in 3.11 and set for removal in 3.13.

    See PEP 594 – Removing dead batteries from the standard library, #91217 and #32410.

    Cc. @freddrake, @facundobatista, @vpython

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions