ip address.py在有效ip地址上获取错误

2024-10-02 16:21:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我在运行Python2.7。我下载了ipaddress.py(https://github.com/phihag/ipaddress)的原始文件。我试着根据这个例子运行一个测试来验证ip地址。但即使是有效的ip地址也似乎是无效的。

>>> import ipaddress
>>> ipaddress.ip_address('127.0.0.1')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "ipaddress.py", line 163, in ip_address
    ' a unicode object?' % address)
ipaddress.AddressValueError: '127.0.0.1' does not appear to be an IPv4 or IPv6 address. Did you pass in a bytes (str in Python 2) instead of a unicode object?
>>> ipaddress.ip_address('192.168.0.1')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "ipaddress.py", line 163, in ip_address
    ' a unicode object?' % address)
ipaddress.AddressValueError: '192.168.0.1' does not appear to be an IPv4 or IPv6 address. Did you pass in a bytes (str in Python 2) instead of a unicode object?

我错过了什么? 谢谢


Tags: inpyipmostobjectaddress地址line