GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — mimetypes CLI writes error messages to stdout instead of stderr · Issue #149682 · python/cpython

mimetypes CLI writes error messages to stdout instead of stderr #149682

New issue
Copy link
New issue
Copy link
Closed
Closed
mimetypes CLI writes error messages to stdout instead of stderr#149682
Copy link

Description

@htjworld
htjworld
opened on May 11, 2026
Issue body actions

Description

The mimetypes command-line interface documentation states:

For each type entry, the script writes a line into the standard output stream. If an unknown type occurs, it writes an error message into the standard error stream and exits with the return code 1.

However, the actual implementation writes all output — including error messages — to stdout via a single print() call:

# Lib/mimetypes.py
if __name__ == '__main__':
    import sys
    results = _main()
    print("\n".join(results))  # errors and normal output mixed into stdout
    sys.exit(any(result.startswith("error: ") for result in results))

Verified behavior:

$ python -m mimetypes foo.unknownext > out.txt 2> err.txt
$ cat out.txt
error: media type unknown for foo.unknownext
$ cat err.txt
(empty)

Error messages go to stdout, stderr is empty — contradicting the docs.

Additional issue: stale docs example

The documentation example shows:

$ python -m mimetypes filename.pict
error: unknown extension of filename.pict

But filename.pict is now recognized:

$ python -m mimetypes filename.pict
type: image/pict encoding: None

The example error message format also doesn't match the actual output ("error: unknown extension of..." vs "error: media type unknown for...").

Proposed fix

Route error messages to stderr in the __main__ block:

if __name__ == '__main__':
    import sys
    results = _main()
    has_error = False
    for result in results:
        if result.startswith("error: "):
            print(result, file=sys.stderr)
            has_error = True
        else:
            print(result)
    sys.exit(has_error)

And update the docs example to use a genuinely unrecognized extension.

Linked PRs

  • gh-131178: Fix mimetypes CLI docs to mention that errors go to stdout #149683

Activity

  1. htjworld commented on May 11, 2026

    @htjworld
    htjworld
    on May 11, 2026
    ContributorAuthor
    More actions

    Closing — the context has been moved to the PR description in #149683.

  2. htjworld
    closed this as completedon May 11, 2026
  3. sobolevn
    added a commit that references this issue on May 31, 2026

    Merge branch 'main' into pythongh-149682-mimetypes-fix-stderr

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.