SeleniumHQ/selenium · error · InvalidArgumentException

Only Proxy objects can be passed in.

Error message

Only Proxy objects can be passed in.

What it means

The proxy property on Options only accepts an instance of selenium.webdriver.common.proxy.Proxy. Passing a dict, a string, or any other type raises InvalidArgumentException. The setter both stores the Proxy and writes its capabilities into the options' caps.

Source

Thrown at py/selenium/webdriver/common/options.py:159

            raise ValueError("Timeout keys can only be one of the following: implicit, pageLoad, script")


class _ProxyDescriptor:
    """Descriptor for proxy property access.

    Returns:
        Proxy if set, otherwise None.
    """

    def __init__(self, name):
        self.name = name

    def __get__(self, obj, cls):
        return obj._proxy

    def __set__(self, obj, value):
        if not isinstance(value, Proxy):
            raise InvalidArgumentException("Only Proxy objects can be passed in.")
        obj._proxy = value
        obj._caps[self.name] = value.to_capabilities()


class BaseOptions(metaclass=ABCMeta):
    """Base class for individual browser options."""

    browser_version = _BaseOptionsDescriptor("browserVersion")
    """Gets and Sets the version of the browser.

    Usage:
        - Get: `self.browser_version`
        - Set: `self.browser_version = value`

    Args:
        value: str

    Returns:

View on GitHub (pinned to aa36b38e69)

Solutions

  1. Construct a Proxy first, then assign: options.proxy = Proxy({'httpProxy': 'host:8080'}).
  2. Configure the Proxy via its properties (proxy.http_proxy = ...) before assigning.

Example fix

# before
options.proxy = {'httpProxy': 'localhost:8080'}  # raises InvalidArgumentException

# after
from selenium.webdriver.common.proxy import Proxy, ProxyType
p = Proxy({'httpProxy': 'localhost:8080'})
p.proxy_type = ProxyType.MANUAL
options.proxy = p
Defensive patterns

Strategy: type-guard

Validate before calling

from selenium.webdriver.common.proxy import Proxy
if not isinstance(proxy_value, Proxy):
    proxy_value = Proxy(proxy_value) if isinstance(proxy_value, dict) else Proxy()
options.proxy = proxy_value

Type guard

from selenium.webdriver.common.proxy import Proxy
def is_proxy(v) -> bool:
    return isinstance(v, Proxy)

Try / catch

from selenium.common.exceptions import InvalidArgumentException
try:
    options.proxy = value
except InvalidArgumentException:
    options.proxy = Proxy(value) if isinstance(value, dict) else Proxy()

Prevention

When it happens

Trigger: Assigning options.proxy = {'httpProxy': 'host:8080'} (a raw dict) instead of a Proxy object. Passing a URL string. Passing None after a Proxy was set also fails the isinstance check.

Common situations: Reading proxy config from JSON/env as a dict and assigning it directly. Assuming the setter accepts the same shape as capabilities. Migrating from older code that used raw dicts.

Related errors


AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14). Data as JSON: /api/errors/e6efa4243ec31a9f. Report an issue: GitHub.