SeleniumHQ/selenium · error · TypeError
`raw` must be a dict, got {type(raw)}
Error message
`raw` must be a dict, got {type(raw)} What it means
The Proxy constructor accepts an optional `raw` argument that must be either None (use defaults) or a dict. Any other type raises TypeError naming the received type. The dict is then interpreted as a raw proxy-capability map (proxyType, httpProxy, noProxy, etc.).
Source
Thrown at py/selenium/webdriver/common/proxy.py:125
socks_username = _ProxyTypeDescriptor("socksUsername", ProxyType.MANUAL)
"""SOCKS proxy username."""
socks_password = _ProxyTypeDescriptor("socksPassword", ProxyType.MANUAL)
"""SOCKS proxy password."""
socks_version = _ProxyTypeDescriptor("socksVersion", ProxyType.MANUAL)
"""SOCKS proxy version."""
def __init__(self, raw: dict | None = None):
"""Creates a new Proxy.
Args:
raw: Raw proxy data. If None, default class values are used.
"""
if raw is None:
return
if not isinstance(raw, dict):
raise TypeError(f"`raw` must be a dict, got {type(raw)}")
if raw.get("proxyType"):
self.proxy_type = ProxyType.load(raw["proxyType"])
if raw.get("httpProxy"):
self.http_proxy = raw["httpProxy"]
if raw.get("noProxy"):
self.no_proxy = raw["noProxy"]
if raw.get("proxyAutoconfigUrl"):
self.proxy_autoconfig_url = raw["proxyAutoconfigUrl"]
if raw.get("sslProxy"):
self.sslProxy = raw["sslProxy"]
if raw.get("autodetect"):
self.auto_detect = raw["autodetect"]
if raw.get("socksProxy"):
self.socks_proxy = raw["socksProxy"]
if raw.get("socksUsername"):
self.socks_username = raw["socksUsername"]
if raw.get("socksPassword"):
self.socks_password = raw["socksPassword"]View on GitHub (pinned to aa36b38e69)
Solutions
- Pass a dict (or None): Proxy({'httpProxy': 'host:8080'}).
- If you have a JSON string, json.loads() it first.
- To copy a Proxy, pass proxy.to_capabilities().
Example fix
# before
p = Proxy('{"httpProxy": "host:8080"}') # str -> TypeError
# after
import json
p = Proxy(json.loads('{"httpProxy": "host:8080"}'))
# or directly
p = Proxy({'httpProxy': 'host:8080'}) Defensive patterns
Strategy: type-guard
Validate before calling
import json
if isinstance(raw, str):
raw = json.loads(raw)
if raw is not None and not isinstance(raw, dict):
raise TypeError('raw must be a dict or None')
proxy = Proxy(raw) Type guard
def is_proxy_raw(v) -> bool:
return v is None or isinstance(v, dict) Try / catch
try:
proxy = Proxy(raw)
except TypeError:
proxy = Proxy(raw if isinstance(raw, dict) else None) Prevention
- json.loads() JSON strings before passing to Proxy.
- Pass dicts only; never scalars, lists, or other Proxy instances.
When it happens
Trigger: Calling Proxy('MANUAL'), Proxy([('httpProxy','host')], Proxy(123), or Proxy(json_string). Passing a JSON-decoded value that is a list or scalar instead of an object.
Common situations: Passing a JSON string instead of a parsed dict. Passing a list of tuples. Passing another Proxy instance instead of its capabilities.
Related errors
- Only Proxy objects can be passed in.
- Autodetect proxy value needs to be a boolean
- no_proxy list must contain only strings
- no_proxy must be a comma-separated string or a list of strin
- Argument to isShown must be of type Element
AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14).
Data as JSON: /api/errors/7277852f6c0b6e5d.
Report an issue: GitHub.