arduino/Arduino · error · LocationParseError

Failed to parse: %s

Error message

Failed to parse: %s

What it means

urllib3.util.parse_url parses URL strings into host/port/scheme components. This LocationParseError is raised when the portion after ':' used as a port is not a string of digits, so the URL's authority component cannot be interpreted as host:port.

Source

Thrown at arduino-core/src/processing/app/i18n/python/requests/packages/urllib3/util.py:154

        path = delim + path_

    # Auth
    if '@' in url:
        auth, url = url.split('@', 1)

    # IPv6
    if url and url[0] == '[':
        host, url = url[1:].split(']', 1)

    # Port
    if ':' in url:
        _host, port = url.split(':', 1)

        if not host:
            host = _host

        if not port.isdigit():
            raise LocationParseError("Failed to parse: %s" % url)

        port = int(port)

    elif not host and url:
        host = url

    if not path:
        return Url(scheme, auth, host, port, path, query, fragment)

    # Fragment
    if '#' in path:
        path, fragment = path.split('#', 1)

    # Query
    if '?' in path:
        path, query = path.split('?', 1)

    return Url(scheme, auth, host, port, path, query, fragment)

View on GitHub (pinned to a0df6e0e83)

Solutions

  1. Fix the URL so any text after the host colon is a numeric port.
  2. Percent-encode special characters in username/password: use urllib.parse.quote on credentials before building the URL, or pass auth=('user','pass') to requests.
  3. Validate with urllib3.util.parse_url in a try/except before use to fail fast with a clearer message.
  4. Check HTTP(S)_PROXY/NO_PROXY env vars for malformed 'host:port' values.

Example fix

// before
url = 'http://user:p@ss:word@example.com/'  # ':word' parsed as port
// after
url = 'http://user:p%40ss%3Aword@example.com/'
Defensive patterns

Strategy: validation

Validate before calling

from urllib3.util import parse_url
def valid_url(u):
    try:
        parsed = parse_url(u)
        return parsed.host is not None and (parsed.port is None or str(parsed.port).isdigit())
    except Exception:
        return False
assert valid_url(url), 'malformed URL: %s' % url

Try / catch

from urllib3.exceptions import LocationParseError
try:
    pool = urllib3.connection_from_url(url)
except LocationParseError as e:
    raise ValueError('Cannot parse URL %r: %s' % (url, e))

Prevention

When it happens

Trigger: Passing URLs like 'http://host:notaport/', 'example.com:8080x', or a password/URL fragment containing a colon in the wrong place ('http://user:p@ss:word@host') so the splitter treats ':word' as a port; passing a bare 'host:path' string to connection_from_url or get_host.

Common situations: Embedding unencoded credentials (password with ':' or '@') in URLs; typos in port numbers; passing proxy strings like 'http://proxy:3128extra' from env vars; forgetting the scheme and passing 'localhost:8080/path' variants that confuse the parser in this vendored version.

Understand the failure class

Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.

Related errors


AI-assisted analysis of arduino/Arduino@a0df6e0e83 (2026-09-06). Data as JSON: /api/errors/c59166be845287b0. Report an issue: GitHub.