python-iptools
python-iptools copied to clipboard
IPRangeList() => TypeError: expected string or bytes-like object, got 'list'
I am optionally using this (to time save a local DHCP address allocation and guess work) and I get this when I run:
django-admin check auth admin
as I am configuring the Admin Site for Development & Local environments.
File "D:\Code\Code Institute\dash-and-do-github\dash_and_do\settings\__init__.py", line 7,
in <module> from .development import *
File "D:\Code\Code Institute\dash-and-do-github\dash_and_do\settings\development.py", line 53,
in <module> INTERNAL_IPS = IpRangeList(['127.0.0.1/24', '192.168.0.0/16'])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Code\Code Institute\dash-and-do-github\venv\Lib\site-packages\iptools\__init__.py", line 414,
in __init__ self.ips = tuple(map(IpRange, args))
^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Code\Code Institute\dash-and-do-github\venv\Lib\site-packages\iptools\__init__.py", line 141,
in __init__ elif ipv4.validate_cidr(start):
^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Code\Code Institute\dash-and-do-github\venv\Lib\site-packages\iptools\ipv4.py", line 257,
in validate_cidr if _CIDR_RE.match(s):
^^^^^^^^^^^^^^^^^
TypeError: expected string or bytes-like object, got 'list'
Your INTERNAL_IPS = IpRangeList(['127.0.0.1/24', '192.168.0.0/16'])
config line should instead be INTERNAL_IPS = IpRangeList('127.0.0.1/24', '192.168.0.0/16')
. See https://python-iptools.readthedocs.io/en/latest/#iptools.IpRangeList for the initializer signature.
There could be a documentation clarity issue here. The docs describe the parameters as *args (list of str and/or tuple) – List of ip addresses or CIDR notation and/or (start, end) tuples of ip addresses.
I can imagine how the use of "list" in that description might lead someone to pass a literal list as you have. The *args
parameter naming is intended to show that iterable unpacking is being used as the list source for this varadic function.