mitmproxy/mitmproxy · error · TypeError

Expected headers to be an iterable or dict, but is {}.

Error message

Expected headers to be an iterable or dict, but is {}.

What it means

Error "Expected headers to be an iterable or dict, but is {}." thrown in mitmproxy/mitmproxy.

Source

Thrown at mitmproxy/http.py:609

    ) -> "Request":
        """
        Simplified API for creating request objects.
        """
        # Headers can be list or dict, we differentiate here.
        if isinstance(headers, Headers):
            pass
        elif isinstance(headers, dict):
            headers = Headers(
                (
                    always_bytes(k, "utf-8", "surrogateescape"),
                    always_bytes(v, "utf-8", "surrogateescape"),
                )
                for k, v in headers.items()
            )
        elif isinstance(headers, Iterable):
            headers = Headers(headers)  # type: ignore
        else:
            raise TypeError(
                "Expected headers to be an iterable or dict, but is {}.".format(
                    type(headers).__name__
                )
            )

        req = cls(
            "",
            0,
            method.encode("utf-8", "surrogateescape"),
            b"",
            b"",
            b"",
            b"HTTP/1.1",
            headers,
            b"",
            None,
            time.time(),
            time.time(),

View on GitHub (pinned to 2ac5b089d9)

When it happens

Trigger: Thrown at mitmproxy/http.py:609 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of mitmproxy/mitmproxy@2ac5b089d9 (2026-08-26). Data as JSON: /api/errors/5dde4020a1bd9896. Report an issue: GitHub.