D4Vinci/Scrapling · error · TypeError
Argument `selector_config` must be a dictionary.
Error message
Argument `selector_config` must be a dictionary.
What it means
Raised by `DynamicFetcher.fetch` (scrapling/fetchers/chrome.py) when the `selector_config` keyword argument is not a dict. selector_config carries arguments forwarded to the final Selector class; it also accepts the legacy `custom_config` key for backward compatibility, but whichever value wins must be a dictionary.
Source
Thrown at scrapling/fetchers/chrome.py:46
:param wait_selector: Wait for a specific CSS selector to be in a specific state.
:param init_script: An absolute path to a JavaScript file to be executed on page creation with this request.
:param locale: Set the locale for the browser if wanted. Defaults to the system default locale.
:param wait_selector_state: The state to wait for the selector given with `wait_selector`. The default state is `attached`.
:param real_chrome: If you have a Chrome browser installed on your device, enable this, and the Fetcher will launch an instance of your browser and use it.
:param cdp_url: Instead of launching a new browser instance, connect to this CDP URL to control real browsers through CDP.
:param google_search: Enabled by default, Scrapling will set a Google referer header.
:param extra_headers: A dictionary of extra headers to add to the request.
:param proxy: The proxy to be used with requests, it can be a string or a dictionary with the keys 'server', 'username', and 'password' only.
:param extra_flags: A list of additional browser flags to pass to the browser on launch.
:param selector_config: The arguments that will be passed in the end while creating the final Selector's class.
:param additional_args: Additional arguments to be passed to Playwright's context as additional settings.
:return: A `Response` object.
"""
selector_config = kwargs.get("selector_config", {}) or kwargs.get(
"custom_config", {}
) # Checking `custom_config` for backward compatibility
if not isinstance(selector_config, dict):
raise TypeError("Argument `selector_config` must be a dictionary.")
kwargs["selector_config"] = {**cls._generate_parser_arguments(), **selector_config}
with DynamicSession(**kwargs) as session:
return session.fetch(url)
@classmethod
async def async_fetch(cls, url: str, **kwargs: Unpack[PlaywrightSession]) -> Response:
"""Opens up a browser and do your request based on your chosen options below.
:param url: Target url.
:param headless: Run the browser in headless/hidden (default), or headful/visible mode.
:param disable_resources: Drop requests for unnecessary resources for a speed boost.
:param blocked_domains: A set of domain names to block requests to. Subdomains are also matched (e.g., ``"example.com"`` blocks ``"sub.example.com"`` too).
:param block_ads: Block requests to ~3,500 known ad/tracking domains. Can be combined with ``blocked_domains``.
:param dns_over_https: Route DNS queries through Cloudflare's DNS-over-HTTPS to prevent DNS leaks when using proxies.
:param useragent: Pass a useragent string to be used. Otherwise the fetcher will generate a real Useragent of the same browser and use it.
:param cookies: Set cookies for the next request.View on GitHub (pinned to 5d213a2d47)
Solutions
- Pass a plain dict: DynamicFetcher.fetch(url, selector_config={'adaptive': True, 'keep_comments': False}).
- If you have an object, convert with vars(obj) or dataclasses.asdict(obj) first.
- Rename custom_config to selector_config (old name still works but only with dict values).
Example fix
# before
DynamicFetcher.fetch(url, selector_config='adaptive=True')
# after
DynamicFetcher.fetch(url, selector_config={'adaptive': True}) Defensive patterns
Strategy: validation
Validate before calling
selector_config = selector_config if isinstance(selector_config, dict) else {}
DynamicFetcher.fetch(url, selector_config=selector_config) Type guard
def is_selector_config(value: object) -> bool:
return isinstance(value, dict) Try / catch
try:
DynamicFetcher.fetch(url, selector_config=cfg)
except TypeError as e:
if "selector_config" in str(e):
return DynamicFetcher.fetch(url, selector_config=dict(cfg)) # or {}
raise Prevention
- Always pass selector_config as a plain dict of Selector kwargs.
- Default to {} (or omit) rather than None.
- Convert config objects with dataclasses.asdict before the call.
When it happens
Trigger: DynamicFetcher.fetch(url, selector_config=SelectorConfig(...)) with a dataclass/object instead of a dict, selector_config='text=True' as a string, or custom_config=[('adaptive', True)] as a list of tuples.
Common situations: Porting code from another library whose config is an object; passing a JSON string straight from a config file; using the old `custom_config` name with a non-dict value.
Related errors
- Argument `selector_config` must be a dictionary.
- 'quality' is only valid when 'image_type' is 'jpeg'.
- Failed to get a response from the page
- Response meta should be dictionary but got {type(meta).__nam
- Unknown parser argument: "{key}"; maybe you meant {cls.parse
AI-assisted analysis of D4Vinci/Scrapling@5d213a2d47 (2026-08-14).
Data as JSON: /api/errors/edb91d6457e09f2d.
Report an issue: GitHub.