[issue9377] socket, PEP 383: Mishandling of non-ASCII bytes in host/domain names

Martin v. Löwis report at bugs.python.org
Sun Oct 17 19:38:56 CEST 2010


Martin v. Löwis <martin at v.loewis.de> added the comment:

Am 15.10.2010 20:03, schrieb David Watson:
> 
> David Watson <baikie at users.sourceforge.net> added the comment:
> 
>> As a further note: I think socket.gethostname() is a special case, since this is just about a local setting (i.e. not related to DNS).
> 
> But the hostname *is* commonly intended to be looked up in the
> DNS or whatever name resolution mechanisms are used locally -
> socket.getfqdn(), for instance, works by looking up the result
> using gethostbyaddr() (actually the C function getaddrinfo(),
> followed by gethostbyaddr()).  So I don't see the rationale for
> treating it differently from the results of gethostbyaddr(),
> getnameinfo(), etc.

The result from gethostname likely comes out of machine-local
configuration. It may have non-ASCII in it, which is then likely
encoded in the local encoding. When looking it up in DNS, IDNA
should be applied.

OTOH, output from gethostbyaddr likely comes out of the DNS itself.
Guessing what encoding it may have is futile - other than guessing
that it really ought to be ASCII.

> I can see the point of returning the characters that were
> intended, but code that looked up the returned name would then
> have to be changed to re-encode it to bytes to avoid the
> round-tripping issue when non-ASCII characters are returned.

Python's socket module is clearly focused on the internet, and
intends to support that well. So if you pass a non-ASCII
string, it will have to encode that using IDNA. If that's
not what you want to get, tough luck.

----------
title: socket, PEP 383: Mishandling of non-ASCII bytes in host/domain names -> socket,	PEP 383: Mishandling of non-ASCII bytes in host/domain names

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9377>
_______________________________________


More information about the Python-bugs-list mailing list