[issue42495] socket.gethostbyaddr raises error if invalid unicode in hosts

2020-11-30 Thread Steve Dower


Steve Dower  added the comment:

This is covered by issue26227

--
resolution:  -> duplicate
stage:  -> resolved
status: open -> closed
superseder:  -> Windows: socket.gethostbyaddr(name) fails for non-ASCII hostname

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42495] socket.gethostbyaddr raises error if invalid unicode in hosts

2020-11-30 Thread Peter Hunt


Peter Hunt  added the comment:

Ah, I just realised it may have been a different dash to the one that can be 
typed with the keyboard.

>From the wiki article (https://en.wikipedia.org/wiki/Dash), using either the 
>"en" or "em" dash will cause the issue for me on Windows.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42495] socket.gethostbyaddr raises error if invalid unicode in hosts

2020-11-29 Thread Christian Heimes


Christian Heimes  added the comment:

I cannot reproduce the issue on Linux:

# echo "127.0.0.2 xn-9q8h" >> /etc/hosts
# python3.8
>>> import socket
>>> socket.gethostbyaddr("127.0.0.2")
('xn-9q8h', [], ['127.0.0.2'])

--
nosy: +christian.heimes
versions:  -Python 3.6, Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42495] socket.gethostbyaddr raises error if invalid unicode in hosts

2020-11-28 Thread Peter Hunt


New submission from Peter Hunt :

If the hosts file contains invalid unicode, then the socket module will break 
when attempting to get the list of hosts. This renders modules such as Flask 
and Django unusable.

Background:
I had a mapping to localghost 
(https://twitter.com/rfreebern/status/1214560971185778693), and Docker 
incorrectly rewrote the hosts file during installation, turning it from 
"127.0.0.1 xn--9q8h" to "127.0.0.1 xn-9q8h".
The socket module was not able to handle that, and was failing with a 
UnicodeDecodeError in Python 3.6+ as it attempted to list the addresses for 
"127.0.0.1".

How to reproduce:
# Add "127.0.0.1 xn-9q8h" to C:/Windows/System32/drivers/etc/hosts

>>> socket.gethostbyaddr('127.0.0.1')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x96 in position 2: 
invalid start byte

Expected:
In Python 2.7 - 3.5, it returns 'xn\u20139q8h'.
I feel returning "xn-9q8h" as a string would be best, but ignoring it could 
be an option.
An alternative would be to raise socket.error.

Full traceback from Flask as an example:

Traceback (most recent call last):
File "__init__.py", line 285, in 
app.run()
File 
"C:\Users\Peter\AppData\Roaming\Python\Python37\site-packages\flask\app.py", 
line 990, in run
run_simple(host, port, self, **options)
File 
"C:\Users\Peter\AppData\Roaming\Python\Python37\site-packages\werkzeug\serving.py",
 line 1052, in run_simple
inner()
File 
"C:\Users\Peter\AppData\Roaming\Python\Python37\site-packages\werkzeug\serving.py",
 line 1005, in inner
fd=fd,
File 
"C:\Users\Peter\AppData\Roaming\Python\Python37\site-packages\werkzeug\serving.py",
 line 848, in make_server
host, port, app, request_handler, passthrough_errors, ssl_context, fd=fd
File 
"C:\Users\Peter\AppData\Roaming\Python\Python37\site-packages\werkzeug\serving.py",
 line 740, in __init__
HTTPServer.__init__(self, server_address, handler)
File "C:\Program Files\Python37\lib\socketserver.py", line 452, in __init__
self.server_bind()
File "C:\Program Files\Python37\lib\http\server.py", line 139, in 
server_bind
self.server_name = socket.getfqdn(host)
File "C:\Program Files\Python37\lib\socket.py", line 676, in getfqdn
hostname, aliases, ipaddrs = gethostbyaddr(name)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x96 in position 2: 
invalid start byte

--
components: Library (Lib), Unicode, Windows
messages: 382029
nosy: Peter92, ezio.melotti, paul.moore, steve.dower, tim.golden, vstinner, 
zach.ware
priority: normal
severity: normal
status: open
title: socket.gethostbyaddr raises error if invalid unicode in hosts
type: behavior
versions: Python 3.10, Python 3.6, Python 3.7, Python 3.8, Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com