Skip to content

gh-93251: Decode localized socket error messages from the locale encoding#154683

Merged
serhiy-storchaka merged 1 commit into
python:mainfrom
serhiy-storchaka:gh-93251-gaierror
Jul 26, 2026
Merged

gh-93251: Decode localized socket error messages from the locale encoding#154683
serhiy-storchaka merged 1 commit into
python:mainfrom
serhiy-storchaka:gh-93251-gaierror

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Jul 25, 2026

Copy link
Copy Markdown
Member

The gai_strerror() and hstrerror() messages were decoded as UTF-8, so gaierror and herror could be replaced with UnicodeDecodeError if the message is localized and the locale encoding is not UTF-8. Decode them from the locale encoding with the "surrogateescape" error handler.

Reproduced with the Ukrainian KOI8-U locale on Linux and the Japanese EUC-JP locale on FreeBSD (where it also made test_logging fail). The new test runs under a number of locales with non-ASCII localized messages, at least one of which is available on each of Linux, FreeBSD, NetBSD, DragonFly BSD, OpenIndiana and macOS.

…e encoding

The gai_strerror() and hstrerror() messages were decoded as UTF-8, so
gaierror and herror could be replaced with UnicodeDecodeError if the
message is localized and the locale encoding is not UTF-8.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@serhiy-storchaka serhiy-storchaka added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels Jul 25, 2026
@serhiy-storchaka
serhiy-storchaka merged commit 5afbb60 into python:main Jul 26, 2026
103 of 106 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14, 3.15.
🐍🍒⛏🤖

@serhiy-storchaka
serhiy-storchaka deleted the gh-93251-gaierror branch July 26, 2026 09:31
@bedevere-app

bedevere-app Bot commented Jul 26, 2026

Copy link
Copy Markdown

GH-154723 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Jul 26, 2026
@bedevere-app

bedevere-app Bot commented Jul 26, 2026

Copy link
Copy Markdown

GH-154724 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Jul 26, 2026
@bedevere-app

bedevere-app Bot commented Jul 26, 2026

Copy link
Copy Markdown

GH-154725 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 bugs and security fixes label Jul 26, 2026
serhiy-storchaka added a commit that referenced this pull request Jul 26, 2026
…le encoding (GH-154683) (GH-154724)

The gai_strerror() and hstrerror() messages were decoded as UTF-8, so
gaierror and herror could be replaced with UnicodeDecodeError if the
message is localized and the locale encoding is not UTF-8.
(cherry picked from commit 5afbb60)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
serhiy-storchaka added a commit that referenced this pull request Jul 26, 2026
…le encoding (GH-154683) (GH-154723)

The gai_strerror() and hstrerror() messages were decoded as UTF-8, so
gaierror and herror could be replaced with UnicodeDecodeError if the
message is localized and the locale encoding is not UTF-8.
(cherry picked from commit 5afbb60)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
serhiy-storchaka added a commit that referenced this pull request Jul 26, 2026
…le encoding (GH-154683) (GH-154725)

The gai_strerror() and hstrerror() messages were decoded as UTF-8, so
gaierror and herror could be replaced with UnicodeDecodeError if the
message is localized and the locale encoding is not UTF-8.
(cherry picked from commit 5afbb60)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant