socket.gethostbyaddr raises error when used on localhost

Flask is unable to run in Python 3.6 onwards (works fine in Python 2.7-3.5), and the only change I've made recently is installing Docker. I've fully reinstalled Python and all the modules during testing.

The issue is being caused by the socket module, when http attempts to start a local server. At one point it expects get the hostname of "127.0.0.1", which raises a UnicodeDecodeError.

Here's an example of the error:

# [Python 3] Test against localhost IP (error)
>>> socket.gethostbyaddr('127.0.0.1')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x96 in position 2: invalid start byte

# [Python 3] Test against localhost
>>> socket.gethostbyaddr('localhost')
('DESKTOP-XXXXXX', [], ['::1'])

# [Python 2] Output of the command
>>> socket.gethostbyaddr('127.0.0.1')
('xn\x969q8h', ['api.genuine.autodesk.com', 'ase.autodesk.com', 'mpa.autodesk.com', 'sv.symcd.com', 'kubernetes.docker.internal'], ['127.0.0.1'])

Here's the full traceback:

Traceback (most recent call last):
  File "__init__.py", line 285, in <module>
    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

I guess it's failing to parse the 'xn\x969q8h' string I see in the Python 2 output, but I've no idea where that's coming from. Running hostname in cmd returns DESKTOP-XXXXX.



from Recent Questions - Stack Overflow https://ift.tt/37nAXQm
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation