On Wed, Sep 22, 2021 at 9:57 AM Andres Torres <andres.torresh...@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 _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/5VHQWIXP5CD5TQ77HTFC7QECWCUNYLKW/ Code of Conduct: http://python.org/psf/codeofconduct/