[issue26227] Windows: socket.gethostbyaddr(name) fails for non-ASCII hostname

STINNER Victor report at bugs.python.org
Fri Mar 13 13:31:04 EDT 2020


STINNER Victor <vstinner at python.org> added the comment:

sock_decode_hostname() of socketmodule.c currently uses PyUnicode_DecodeFSDefault() on Windows. PyUnicode_DecodeFSDefault() uses UTF-8 by default (PEP 529).

I understand that the ANSI code page should be used instead of UTF-8.

Would it work to use PyUnicode_DecodeLocale(name, "surrogatepass")? It's implemented with mbstowcs(), but I don't recall which encoding it uses on Windows.

Or can we use PyUnicode_DecodeMBCS(name, strlen(name), "surrogatepass")?

--

I understand that setting PYTHONLEGACYWINDOWSFSENCODING environment variable to 1 should work around the issue.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue26227>
_______________________________________


More information about the Python-bugs-list mailing list