【发布时间】:2016-11-23 23:58:23
【问题描述】:
我只是在以下位置运行示例:https://docs.python.org/3/howto/ipaddress.html#ipaddress-howto
但是,在以下示例中:
import ipaddress
net4 = ipaddress.ip_network("192.0.2.0/24")
for x in net4.hosts():
print(x)
我收到以下错误:
AddressValueErrorTraceback (most recent call last)
<ipython-input-18-256ed42a96d9> in <module>()
1 import ipaddress
2
----> 3 net4 = ipaddress.ip_network("192.0.2.0/24")
4 for x in net4.hosts():
5 print(x)
/usr/local/lib/python2.7/dist-packages/ipaddress.pyc in ip_network(address, strict)
197 '%r does not appear to be an IPv4 or IPv6 network. '
198 'Did you pass in a bytes (str in Python 2) instead of'
--> 199 ' a unicode object?' % address)
200
201 raise ValueError('%r does not appear to be an IPv4 or IPv6 network' %
AddressValueError: '192.0.2.0/24' does not appear to be an IPv4 or IPv6 network. Did you pass in a bytes (str in Python 2) instead of a unicode object?
我在这里错过了什么吗(我使用的是 python 2.7)?谢谢!
【问题讨论】:
标签: python-2.7 ip