gpt4 book ai didi

python 3 : ipaddr/netaddr modules

转载 作者:行者123 更新时间:2023-11-28 20:29:20 25 4
gpt4 key购买 nike

我必须在这里做错事......我目前正在尝试使用内置模块验证 ip 是否在特定子网内。

我正在使用 activepython:

ActivePython 3.1.2.3 (ActiveState Software Inc.) based onPython 3.1.2 (r312:79147, Mar 22 2010, 12:20:29) [MSC v.1500 32 bit (Intel)] on win32

在变更日志中有这个:

Python News(editors: check NEWS.help for information about editing NEWS using ReST.)What's New in Python 3.1.2?Release date: 2010-03-20----- snip -----Removed the ipaddr module. Issue #3613: base64.{encode,decode}string are now called System Message: WARNING/2 (, line 706)----- snip -----Issue #3959: The ipaddr module has been added to the standard library. Contributed by Google.

那个和其他谷歌搜索让我相信 ipaddr 是一个内置的但是:

>>> import ipaddrTraceback (most recent call last):  File "", line 1, in ImportError: No module named ipaddr>>> from ipaddr import *Traceback (most recent call last):  File "", line 1, in ImportError: No module named ipaddr

所以我想我会安装 netaddr 并尝试使用它,而我从 netaddr 得到的是:

>>> import netaddrTraceback (most recent call last):  File "", line 1, in   File "C:\Python31\lib\site-packages\netaddr\__init__.py", line 18, in     from netaddr.ip import IPAddress, IPNetwork, IPRange, all_matching_cidrs, \  File "C:\Python31\lib\site-packages\netaddr\ip\__init__.py", line 1877, in     IPV6_LOOPBACK = IPAddress('::1')  File "C:\Python31\lib\site-packages\netaddr\ip\__init__.py", line 262, in __init__    self.value = addr  File "C:\Python31\lib\site-packages\netaddr\ip\__init__.py", line 292, in _set_value    % value)netaddr.core.AddrFormatError: failed to detect IP version: '::1'

我感到相当沮丧,我不确定从这里该何去何从...建议?

最佳答案

netaddr 尚不支持 Python 3.x(如 README 中所述)。

但是,它将在即将发布的版本 (0.7.5) 中使用。我会以此为暗示,我应该快点把它弄出门来!

我在此处的项目错误跟踪器上添加了一张票:-

http://code.google.com/p/netaddr/issues/detail?id=55

谢谢。

关于 python 3 : ipaddr/netaddr modules,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2714942/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com