elastic-transport-python icon indicating copy to clipboard operation
elastic-transport-python copied to clipboard

test_url_to_node_config[https://[::1]:0/-https://[::1]:0-] fails with latest release of urllib3 (urllib3==1.26.13)

Open danigm opened this issue 2 years ago • 1 comments

The last version of urllib3, 1.26.13 parses differently the port 0 in urls and that breaks the tests:

https://github.com/urllib3/urllib3/releases/tag/1.26.13

This is the test that's failing:

_________________________________________________________ test_url_to_node_config[https://[::1]:0/-https://[::1]:0-] __________________________________________________________

url = 'https://[::1]:0/', node_base_url = 'https://[::1]:0', path_prefix = ''

    @pytest.mark.parametrize(
        ["url", "node_base_url", "path_prefix"],
        [
            ("http://localhost:3002", "http://localhost:3002", ""),
            ("http://127.0.0.1:3002", "http://127.0.0.1:3002", ""),
            ("http://127.0.0.1:3002/", "http://127.0.0.1:3002", ""),
            (
                "http://127.0.0.1:3002/path-prefix",
                "http://127.0.0.1:3002/path-prefix",
                "/path-prefix",
            ),
            (
                "http://localhost:3002/url-prefix/",
                "http://localhost:3002/url-prefix",
                "/url-prefix",
            ),
            ("http://[::1]:3002/url-prefix", "http://[::1]:3002/url-prefix", "/url-prefix"),
            ("https://[::1]:0/", "https://[::1]:0", ""),
        ],
    )
    def test_url_to_node_config(url, node_base_url, path_prefix):
>       node_config = url_to_node_config(url)

tests/test_client_utils.py:166: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

url = 'https://[::1]:0/', use_default_ports_for_scheme = False

    def url_to_node_config(
        url: str, use_default_ports_for_scheme: bool = False
    ) -> NodeConfig:
        """Constructs a :class:`elastic_transport.NodeConfig` instance from a URL.
        If a username/password are specified in the URL they are converted to an
        'Authorization' header.
    
        :param url: URL to transform into a NodeConfig.
        :param use_default_ports_for_scheme: If 'True' will resolve default ports for the given scheme.
        """
        try:
            parsed_url = parse_url(url)
        except LocationParseError:
            raise ValueError(f"Could not parse URL {url!r}") from None
    
        # Only fill in a default port for HTTP and HTTPS
        # when we know the scheme is one of those two.
        parsed_port: Optional[int] = parsed_url.port  # type: ignore[assignment]
        if (
            parsed_url.port is None
            and parsed_url.scheme is not None
            and use_default_ports_for_scheme is True
        ):
            if parsed_url.scheme == "https":
                parsed_port = 443
            elif parsed_url.scheme == "http":
                parsed_port = 80
    
        if any(
            component in (None, "")
            for component in (parsed_url.scheme, parsed_url.host, parsed_port)
        ):
>           raise ValueError(
                "URL must include a 'scheme', 'host', and 'port' component (ie 'https://localhost:9200')"
            )
E           ValueError: URL must include a 'scheme', 'host', and 'port' component (ie 'https://localhost:9200')

danigm avatar Dec 05 '22 11:12 danigm

This is a bug that will get fixed in urllib3 1.26.14. There's no release date yet though, sorry.

pquentin avatar Dec 16 '22 05:12 pquentin

This should be closed

bnavigator avatar Dec 12 '24 16:12 bnavigator