D4Vinci/Scrapling · error · TypeError
Nested Iterables are not accepted, only iterables of tag nam
Error message
Nested Iterables are not accepted, only iterables of tag names are accepted
What it means
Inside find_all(), an iterable argument (list/tuple/set) contained at least one non-string element. scrapling only accepts flat iterables of tag names — a nested list, or a list containing ints/Patterns/Selectars, triggers this TypeError before any tree traversal happens.
Source
Thrown at scrapling/parser.py:726
return Selectors()
if not args and not kwargs:
raise TypeError("You have to pass something to search with, like tag name(s), tag attributes, or both.")
attributes: Dict[str, Any] = dict()
tags: Set[str] = set()
patterns: Set[Pattern] = set()
results, functions, selectors = Selectors(), [], []
# Brace yourself for a wonderful journey!
for arg in args:
if isinstance(arg, str):
tags.add(arg)
elif type(arg) in (list, tuple, set):
arg = cast(Iterable, arg) # Type narrowing for type checkers like pyright
if not all(map(lambda x: isinstance(x, str), arg)):
raise TypeError("Nested Iterables are not accepted, only iterables of tag names are accepted")
tags.update(set(arg))
elif isinstance(arg, dict):
if not all([(isinstance(k, str) and isinstance(v, str)) for k, v in arg.items()]):
raise TypeError(
"Nested dictionaries are not accepted, only string keys and string values are accepted"
)
attributes.update(arg)
elif isinstance(arg, re_Pattern):
patterns.add(arg)
elif callable(arg):
if len(signature(arg).parameters) > 0:
functions.append(arg)
else:
raise TypeError(
"Callable filter function must have at least one argument to take `Selector` objects."View on GitHub (pinned to 5d213a2d47)
Solutions
- Flatten the iterable first: itertools.chain.from_iterable(nested) or a small flatten helper.
- Keep regex Patterns out of lists — pass them as standalone args: find_all(['div'], re.compile(r'h\d')).
- Coerce everything to str up front if the list mixes str and int from external data: [str(x) for x in items].
Example fix
# before selector.find_all([['div', 'span'], 'p']) # TypeError # after from itertools import chain selector.find_all(list(chain.from_iterable([['div', 'span'], ['p']])))
Defensive patterns
Strategy: validation
Validate before calling
from itertools import chain
def flatten_tags(items):
flat = chain.from_iterable(x if isinstance(x, (list, tuple, set)) else [x] for x in items)
return [t for t in flat if isinstance(t, str)]
selector.find_all(flatten_tags(nested_tags)) Type guard
def is_flat_str_iterable(items) -> bool:
return all(isinstance(x, str) for x in items) Try / catch
try:
selector.find_all(tags_arg)
except TypeError as e:
if 'Nested Iterables' in str(e):
tags_arg = list(chain.from_iterable(tags_arg))
results = selector.find_all(tags_arg)
else:
raise Prevention
- Flatten iterables of tag names at the boundary where they enter your code.
- Keep regex Patterns and callables as separate find_all args, never inside lists.
When it happens
Trigger: find_all([['div', 'span'], 'p']), find_all(['div', 42]), or find_all((name for name in names)) where the generator yields non-strings.
Common situations: Flattening logic that missed a level of nesting; mixing tag names with regex Patterns in one list instead of passing the Pattern as a separate argument.
Related errors
- Nested dictionaries are not accepted, only string keys and s
- Argument with type "{type(arg)}" is not accepted, please rea
- Only string values are accepted for arguments
- Response meta should be dictionary but got {type(meta).__nam
- Invalid proxy string: {proxy_string}
AI-assisted analysis of D4Vinci/Scrapling@5d213a2d47 (2026-08-14).
Data as JSON: /api/errors/b6f7028d426557b4.
Report an issue: GitHub.