{"id":"f03bf25884eac75d","repo":"encode/httpx","slug":"invalid-auth-argument-auth-r","errorCode":null,"errorMessage":"Invalid \"auth\" argument: {auth!r}","messagePattern":"Invalid \"auth\" argument: (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"httpx/_client.py","lineNumber":455,"sourceCode":"        Merge a queryparams argument together with any queryparams on the client,\n        to create the queryparams used for the outgoing request.\n        \"\"\"\n        if params or self.params:\n            merged_queryparams = QueryParams(self.params)\n            return merged_queryparams.merge(params)\n        return params\n\n    def _build_auth(self, auth: AuthTypes | None) -> Auth | None:\n        if auth is None:\n            return None\n        elif isinstance(auth, tuple):\n            return BasicAuth(username=auth[0], password=auth[1])\n        elif isinstance(auth, Auth):\n            return auth\n        elif callable(auth):\n            return FunctionAuth(func=auth)\n        else:\n            raise TypeError(f'Invalid \"auth\" argument: {auth!r}')\n\n    def _build_request_auth(\n        self,\n        request: Request,\n        auth: AuthTypes | UseClientDefault | None = USE_CLIENT_DEFAULT,\n    ) -> Auth:\n        auth = (\n            self._auth if isinstance(auth, UseClientDefault) else self._build_auth(auth)\n        )\n\n        if auth is not None:\n            return auth\n\n        username, password = request.url.username, request.url.password\n        if username or password:\n            return BasicAuth(username=username, password=password)\n\n        return Auth()","sourceCodeStart":437,"sourceCodeEnd":473,"githubUrl":"https://github.com/encode/httpx/blob/b5addb64f0161ff6bfe94c124ef76f6a1fba5254/httpx/_client.py#L437-L473","documentation":"Raised as TypeError by BaseClient._build_auth when the 'auth' argument is not None, not a (username, password) tuple, not an httpx.Auth instance, and not callable. httpx supports exactly those four shapes and rejects anything else.","triggerScenarios":"Passing an unsupported value to auth=, e.g. client.get(url, auth=\"user:pass\"), auth={\"user\":\"x\"}, auth=[\"u\",\"p\",\"extra\"], or auth=123.","commonSituations":"Passing credentials as a 'user:password' string instead of a tuple; passing a dict; passing a list of more than two elements; mis-typed config variables.","solutions":["Pass a 2-tuple: auth=(\"user\", \"password\").","Or pass an httpx.BasicAuth(...) / httpx.DigestAuth(...) instance.","Or pass a callable taking a Request and returning a Request."],"exampleFix":"// before\nclient.get(url, auth=\"alice:s3cret\")\n// after\nclient.get(url, auth=(\"alice\", \"s3cret\"))","handlingStrategy":"type-guard","validationCode":"import httpx\nfrom typing import Any\n\ndef is_valid_auth(auth: Any) -> bool:\n    return (\n        auth is None\n        or isinstance(auth, tuple)\n        or isinstance(auth, httpx.Auth)\n        or callable(auth)\n    )\n\n# before the request\nassert is_valid_auth(auth), f\"auth must be None|tuple|httpx.Auth|callable, got {type(auth)!r}\"\nclient.get(url, auth=auth)","typeGuard":"from typing import Any\nimport httpx\n\ndef is_valid_auth(auth: Any) -> bool:\n    return (\n        auth is None\n        or isinstance(auth, tuple)\n        or isinstance(auth, httpx.Auth)\n        or callable(auth)\n    )","tryCatchPattern":"try:\n    client.get(url, auth=auth)\nexcept TypeError as exc:\n    raise ValueError(f\"Invalid auth credential format: {auth!r}\") from exc","preventionTips":["Always pass credentials as a (username, password) tuple or an httpx.Auth instance.","Never pass a 'user:pass' string or dict to auth=.","Type-check auth values that originate from config files."],"tags":["authentication","config","type-error"],"analyzedSha":"b5addb64f0161ff6bfe94c124ef76f6a1fba5254","analyzedAt":"2026-08-04T19:32:56.768Z","schemaVersion":2}