ValueError:"10.0.0.0/24"似乎不是IPv4或IPv6网络 [英] ValueError: '10.0.0.0/24' does not appear to be an IPv4 or IPv6 network

查看:61
本文介绍了ValueError:"10.0.0.0/24"似乎不是IPv4或IPv6网络的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Python中的IP子网/IP地址.我使用ipaddress模块创建了Python代码.当我在pycharm IDE中运行代码时,它可以正常工作.但是,当我通过键入python test.py在命令提示符下运行时,它显示了以下错误.

I want to work with IP subnets / IP addresses in Python. I created the Python code using the ipaddress module. When I run the code in the pycharm IDE, it works fine. But when I run on the command prompt by typing python test.py, it shows the following error.

ValueError: '10.0.0.0/24' does not appear to be an IPv4 or IPv6 network

test.py :

import ipaddress
srcIp = ipaddress.ip_network("10.0.0.0/24")
print(srcIp)

推荐答案

如果您使用Unicode字符串,它似乎在Python 2.7中有效.

It seems to work in Python 2.7, if you use a Unicode string.

import ipaddress
srcIp = ipaddress.ip_network(u'10.0.0.0/24')
print srcIp

这篇关于ValueError:"10.0.0.0/24"似乎不是IPv4或IPv6网络的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆