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 — Docs: subprocess text mode does not say that the default encoding is a guess about the child process · Issue #158633 · python/cpython

Docs: subprocess text mode does not say that the default encoding is a guess about the child process #158633

New issue
Copy link
New issue
Copy link
Open
#158634
Open
Docs: subprocess text mode does not say that the default encoding is a guess about the child process#158633
#158634
Copy link
Labels
docsDocumentation in the Doc dirDocumentation in the Doc dirtopic-subprocessSubprocess issues.Subprocess issues.

Description

@AlKor13
AlKor13
opened on Oct 3, 2026
Issue body actions

Documentation

subprocess's text-mode documentation says which encoding is used, but not that the value is a guess about the child process. In gh-105312 @zooba said a docs enhancement would be considered, and described what it should say:

I would add a warning that it will guess the encoding of the child process and you'll get garbage if it guesses wrong, and you are always recommended to specify the encoding to use (on all platforms, though you are most likely to get into trouble on Windows).

and, on the Windows specifics:

It's worse on Windows, because there have been 2-3 common defaults over time, and even GetConsoleOutputCP is only correct if you know that the child process uses it.

This is the follow-up issue for that. @kunom, who filed gh-105312, supported it there.

What the docs say today

Doc/library/subprocess.rst, the frequently-used-arguments section:

If encoding or errors are specified, or text (also known as universal_newlines) is true, the file objects stdin, stdout and stderr will be opened in text mode using the encoding and errors specified in the call or the defaults for :class:io.TextIOWrapper.

Accurate, and it never says that the default is unrelated to what the child writes, or what the failure looks like when they disagree.

Why the failure is hard to attribute

Measured on Windows 11, Python 3.12.8, ANSI code page cp1251, console output code page cp866 — two different defaults in force at the same time, so no single value is correct for every child of one process:

subprocess.run([sys.executable, "-c", "print('Тест')"], capture_output=True, text=True).stdout
# 'Тест'                      the child wrote UTF-8, text=True decoded cp1251

subprocess.run("echo Тест", shell=True, text=True, stdout=subprocess.PIPE).stdout
# '’Ґбв'                          the child wrote cp866, text=True decoded cp1251

Under UTF-8 mode, which :pep:686 makes the default in 3.15, the second one stops being wrong text and becomes an exception instead:

PYTHONUTF8=1 -> UnicodeDecodeError: 'utf-8' codec can't decode byte 0x92 in position 0

The traceback for that comes from inside the stream reader rather than from the caller's code, which is what sends people looking for a bug in subprocess rather than at their own missing encoding=. That is the part a warning in the docs would save.

Proposed change

A .. warning:: in frequently-used-arguments, right after the paragraph that describes binary mode, keeping to @zooba's framing: the default is a guess, specify encoding on every platform, and on Windows a console child is read with the console output code page while a Python child can be told what to use through :envvar:PYTHONUTF8 / :envvar:PYTHONIOENCODING. No behaviour change, no new API, and Popen's section already points at this one.

Happy to open the PR — a draft is ready and I will link it here.

Linked PRs

  • gh-158633: say that subprocess text mode guesses the child's encoding #158634

Activity

  1. AlKor13
    added a commit that references this issue on Oct 3, 2026

    pythongh-158633: say that subprocess text mode guesses the child's en…

    d1ea9b3
  2. aisk
    added
    docsDocumentation in the Doc dirDocumentation in the Doc dir
    topic-subprocessSubprocess issues.Subprocess issues.
    on Oct 3, 2026
  3. github-project-automation
    added this to docs issueson Oct 3, 2026
  4. github-project-automation
    moved this to Todo in docs issueson Oct 3, 2026
  5. kevinprimeraquecreo-stack
    added this to Project_VKon Oct 18, 2026
  6. github-project-automation
    moved this to Todo in Project_VKon Oct 18, 2026
  7. github-project-automation
    moved this from Todo to In progress in Project_VKon Oct 18, 2026
  8. kevinprimeraquecreo-stack
    added this to Project_VKon Oct 18, 2026
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

    docsDocumentation in the Doc dirDocumentation in the Doc dirtopic-subprocessSubprocess issues.Subprocess issues.

    Projects

    • docs issues
      Status
      Todo
      Show more project fields

    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.