Make localhost an acceptable parameter to ipaddress.IPv4Address address parameter
Title is pretty self explanatory. Right the following causes an error: ```py
ipaddress.IPv4Address('localhost') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\ProgramData\Anaconda3\lib\ipaddress.py", line 1252, in __init__ self._ip = self._ip_int_from_string(addr_str) File "C:\ProgramData\Anaconda3\lib\ipaddress.py", line 1144, in _ip_int_from_string raise AddressValueError("Expected 4 octets in %r" % ip_str) ipaddress.AddressValueError: Expected 4 octets in 'localhost'
But it should just either convert `localhost` to `127.0.0.1` or maybe store `localhost` internally somehow.
On Wed, Sep 22, 2021 at 9:57 AM Andres Torres <andres.torreshalo@gmail.com> wrote:
Title is pretty self explanatory.
Right the following causes an error: ```py
ipaddress.IPv4Address('localhost') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\ProgramData\Anaconda3\lib\ipaddress.py", line 1252, in __init__ self._ip = self._ip_int_from_string(addr_str) File "C:\ProgramData\Anaconda3\lib\ipaddress.py", line 1144, in _ip_int_from_string raise AddressValueError("Expected 4 octets in %r" % ip_str) ipaddress.AddressValueError: Expected 4 octets in 'localhost'
But it should just either convert `localhost` to `127.0.0.1` or maybe store `localhost` internally somehow.
"localhost" is a name that can be resolved, and by default, it resolves to 127.0.0.1. But it's not itself an IP address. If you want to be able to look up names, try socket.gethostbyname(), which is quite happy to accept IP addresses (and will return them unchanged). Be aware that it may take time to get a result back. ChrisA
participants (2)
-
Andres Torres
-
Chris Angelico