Skip to content

Error parsing some ipv6 #899

@Kludex

Description

@Kludex

Originally opened by @yuanyehome on 2025-05-15 03:02:21 in encode/httpx

httpx==0.28.1
I've got the error below:

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/dist-packages/httpx/_urlparse.py", line 415, in normalize_port
    port_as_int = int(port)
                  ^^^^^^^^^
ValueError: invalid literal for int() with base 10: ':'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/xxx/deepseek-v3-example.py", line 14, in <module>
    client = OpenAI(
             ^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/openai/_client.py", line 136, in __init__
    super().__init__(
  File "/usr/local/lib/python3.11/dist-packages/openai/_base_client.py", line 855, in __init__
    self._client = http_client or SyncHttpxClientWrapper(
                                  ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/openai/_base_client.py", line 785, in __init__
    super().__init__(**kwargs)
  File "/usr/local/lib/python3.11/dist-packages/httpx/_client.py", line 697, in __init__
    self._mounts: dict[URLPattern, BaseTransport | None] = {
                                                           ^
  File "/usr/local/lib/python3.11/dist-packages/httpx/_client.py", line 698, in <dictcomp>
    URLPattern(key): None
    ^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/httpx/_utils.py", line 172, in __init__
    url = URL(pattern)
          ^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/httpx/_urls.py", line 117, in __init__
    self._uri_reference = urlparse(url, **kwargs)
                          ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/httpx/_urlparse.py", line 327, in urlparse
    parsed_port: int | None = normalize_port(port, scheme)
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/httpx/_urlparse.py", line 417, in normalize_port
    raise InvalidURL(f"Invalid port: {port!r}")
httpx.InvalidURL: Invalid port: ':'

And I printed several variables, which shows some error in parsing ipv6 url:

url='all://[fe80::/10]'
URL_REGEX=re.compile('(?:(?P<scheme>([a-zA-Z][a-zA-Z0-9+.-]*)?):)?(?://(?P<authority>[^/?#]*))?(?P<path>[^?#]*)(?:\\?(?P<query>[^#]*))?(?:#(?P<fragment>.*))?')
url_match=<re.Match object; span=(0, 17), match='all://[fe80::/10]'>
url_dict={'scheme': 'all', 'authority': '[fe80::', 'path': '/10]', 'query': None, 'fragment': None}
host='[fe80'
port=':'

Will this be fixed?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions