# Buggy code
def __init__(
    self, url: typing.Union["URL", str, RawURL] = "", params: QueryParamTypes = None
) -> None:
    if isinstance(url, (str, tuple)):
        if isinstance(url, tuple):
            raw_scheme, raw_host, port, raw_path = url
            scheme = raw_scheme.decode("ascii")
            host = raw_host.decode("ascii")
            port_str = "" if port is None else f":{port}"
            path = raw_path.decode("ascii")
            url = f"{scheme}://{host}{port_str}{path}"

        try:
            self._uri_reference = rfc3986.iri_reference(url).encode()
        except rfc3986.exceptions.InvalidAuthority as exc:
            raise InvalidURL(message=str(exc)) from None

        if self.is_absolute_url:
            # We don't want to normalize relative URLs, since doing so
            # removes any leading `../` portion.
            self._uri_reference = self._uri_reference.normalize()
    elif isinstance(url, URL):
        self._uri_reference = url._uri_reference
    else:
        raise TypeError(
            f"Invalid type for url.  Expected str or httpx.URL, got {type(url)}"
        )

    # Add any query parameters, merging with any in the URL if needed.
    if params:
        if self._uri_reference.query:
            url_params = QueryParams(self._uri_reference.query)
            url_params.update(params)
            query_string = str(url_params)
        else:
            query_string = str(QueryParams(params))
        self._uri_reference = self._uri_reference.copy_with(query=query_string)


# Traceback (httpcore.ConnectError)
<Response [200]>
<Response [200]>
<Response [200 OK]>
Traceback (most recent call last):
File "/home/user/repos/lb-test/.venv/lib/python3.7/site-packages/httpx/_exceptions.py", line 339, in map_exceptions
yield
File "/home/user/repos/lb-test/.venv/lib/python3.7/site-packages/httpx/_client.py", line 858, in _send_single_request
ext={"timeout": timeout.as_dict()},
File "/home/user/repos/lb-test/.venv/lib/python3.7/site-packages/httpcore/_sync/connection_pool.py", line 195, in request
method, url, headers=headers, stream=stream, ext=ext
File "/home/user/repos/lb-test/.venv/lib/python3.7/site-packages/httpcore/_sync/connection.py", line 87, in request
self.socket = self._open_socket(timeout)
File "/home/user/repos/lb-test/.venv/lib/python3.7/site-packages/httpcore/_sync/connection.py", line 113, in _open_socket
local_address=self.local_address,
File "/home/user/repos/lb-test/.venv/lib/python3.7/site-packages/httpcore/_backends/sync.py", line 144, in open_tcp_stream
return SyncSocketStream(sock=sock)
File "/home/user/.local/share/pyenv/versions/3.7.6/lib/python3.7/contextlib.py", line 130, in __exit__
self.gen.throw(type, value, traceback)
File "/home/user/repos/lb-test/.venv/lib/python3.7/site-packages/httpcore/_exceptions.py", line 12, in map_exceptions
raise to_exc(exc) from None
httpcore.ConnectError: [Errno -2] Name or service not known

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "kek.py", line 11, in <module>
print(httpx.get(url6))
File "/home/user/repos/lb-test/.venv/lib/python3.7/site-packages/httpx/_api.py", line 193, in get
trust_env=trust_env,
File "/home/user/repos/lb-test/.venv/lib/python3.7/site-packages/httpx/_api.py", line 104, in request
allow_redirects=allow_redirects,
File "/home/user/repos/lb-test/.venv/lib/python3.7/site-packages/httpx/_client.py", line 722, in request
request, auth=auth, allow_redirects=allow_redirects, timeout=timeout
File "/home/user/repos/lb-test/.venv/lib/python3.7/site-packages/httpx/_client.py", line 758, in send
history=[],
File "/home/user/repos/lb-test/.venv/lib/python3.7/site-packages/httpx/_client.py", line 795, in _send_handling_auth
history=history,
File "/home/user/repos/lb-test/.venv/lib/python3.7/site-packages/httpx/_client.py", line 823, in _send_handling_redirects
response = self._send_single_request(request, timeout)
File "/home/user/repos/lb-test/.venv/lib/python3.7/site-packages/httpx/_client.py", line 858, in _send_single_request
ext={"timeout": timeout.as_dict()},
File "/home/user/.local/share/pyenv/versions/3.7.6/lib/python3.7/contextlib.py", line 130, in __exit__
self.gen.throw(type, value, traceback)
File "/home/user/repos/lb-test/.venv/lib/python3.7/site-packages/httpx/_exceptions.py", line 356, in map_exceptions
raise mapped_exc(message, **kwargs) from exc  # type: ignore
httpx.ConnectError: [Errno -2] Name or service not known

# Fixed code
def __init__(
    self, url: typing.Union["URL", str, RawURL] = "", params: QueryParamTypes = None
) -> None:
    if isinstance(url, (str, tuple)):
        if isinstance(url, tuple):
            raw_scheme, raw_host, port, raw_path = url
            scheme = raw_scheme.decode("ascii")
            host = raw_host.decode("ascii")
            if host and ":" in host and host[0] != "[":
                # it's an IPv6 address, so it should be enclosed in "[" and "]"
                # ref: https://tools.ietf.org/html/rfc2732#section-2
                # ref: https://tools.ietf.org/html/rfc3986#section-3.2.2
                host = f"[{host}]"
            port_str = "" if port is None else f":{port}"
            path = raw_path.decode("ascii")
            url = f"{scheme}://{host}{port_str}{path}"

        try:
            self._uri_reference = rfc3986.iri_reference(url).encode()
        except rfc3986.exceptions.InvalidAuthority as exc:
            raise InvalidURL(message=str(exc)) from None

        if self.is_absolute_url:
            # We don't want to normalize relative URLs, since doing so
            # removes any leading `../` portion.
            self._uri_reference = self._uri_reference.normalize()
    elif isinstance(url, URL):
        self._uri_reference = url._uri_reference
    else:
        raise TypeError(
            f"Invalid type for url.  Expected str or httpx.URL, got {type(url)}"
        )

    # Add any query parameters, merging with any in the URL if needed.
    if params:
        if self._uri_reference.query:
            url_params = QueryParams(self._uri_reference.query)
            url_params.update(params)
            query_string = str(url_params)
        else:
            query_string = str(QueryParams(params))
        self._uri_reference = self._uri_reference.copy_with(query=query_string)