SeleniumHQ/selenium · error · TypeError

no_proxy must be a comma-separated string or a list of strin

Error message

no_proxy must be a comma-separated string or a list of strings

What it means

When converting proxy settings to BiDi format (to_bidi_dict), if noProxy is set but is neither a string nor a list, TypeError is raised. Only a comma-separated string or a list of strings is accepted. This runs only when proxyType is 'manual'.

Source

Thrown at py/selenium/webdriver/common/proxy.py:214

        if proxy_type == "manual":
            if self.httpProxy:
                result["httpProxy"] = self.httpProxy
            if self.sslProxy:
                result["sslProxy"] = self.sslProxy
            if self.socksProxy:
                result["socksProxy"] = self.socksProxy
            if self.socksVersion is not None:
                result["socksVersion"] = self.socksVersion
            if self.noProxy:
                # Convert comma-separated string to list
                if isinstance(self.noProxy, str):
                    result["noProxy"] = [host.strip() for host in self.noProxy.split(",") if host.strip()]
                elif isinstance(self.noProxy, list):
                    if not all(isinstance(h, str) for h in self.noProxy):
                        raise TypeError("no_proxy list must contain only strings")
                    result["noProxy"] = self.noProxy
                else:
                    raise TypeError("no_proxy must be a comma-separated string or a list of strings")

        elif proxy_type == "pac":
            if self.proxyAutoconfigUrl:
                result["proxyAutoconfigUrl"] = self.proxyAutoconfigUrl

        return result

View on GitHub (pinned to aa36b38e69)

Solutions

  1. Set no_proxy to a comma-separated string ('localhost,example.com') or a list of strings.
  2. Convert other iterables to a list: list(value).

Example fix

# before
proxy.no_proxy = ('localhost', 'example.com')  # tuple
proxy.to_bidi_dict()  # raises TypeError

# after
proxy.no_proxy = 'localhost,example.com'
# or
proxy.no_proxy = ['localhost', 'example.com']
Defensive patterns

Strategy: validation

Validate before calling

if not isinstance(no_proxy, (str, list)):
    no_proxy = list(no_proxy) if hasattr(no_proxy, '__iter__') else str(no_proxy)
proxy.no_proxy = no_proxy

Type guard

def is_valid_no_proxy(v) -> bool:
    return isinstance(v, (str, list))

Try / catch

try:
    proxy.to_bidi_dict()
except TypeError:
    proxy.no_proxy = ','.join(proxy.no_proxy) if isinstance(proxy.no_proxy, (list, tuple, set)) else ''
    proxy.to_bidi_dict()

Prevention

When it happens

Trigger: Setting proxy.no_proxy = 8080 (int), proxy.no_proxy = ('a','b') (tuple), proxy.no_proxy = {'host':1} (dict), then calling proxy.to_bidi_dict(). The MANUAL setter accepts any truthy value, so the error surfaces only at BiDi conversion.

Common situations: Assigning a tuple, set, or int to no_proxy. Storing a single host as a bare value. Using a frozenset from config.

Related errors


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