{"record":{"id":"2db9511a196b24c2","repo":"psf/requests","slug":"name-name-r-domain-domain-r-path-path-r","errorCode":null,"errorMessage":"name={name!r}, domain={domain!r}, path={path!r}","messagePattern":"name=(.+?), domain=(.+?), path=(.+?)","errorType":"exception","errorClass":"KeyError","httpStatus":null,"severity":"error","filePath":"src/requests/cookies.py","lineNumber":421,"sourceCode":"    ) -> str | None:\n        \"\"\"Requests uses this method internally to get cookie values.\n\n        If there are conflicting cookies, _find arbitrarily chooses one.\n        See _find_no_duplicates if you want an exception thrown if there are\n        conflicting cookies.\n\n        :param name: a string containing name of cookie\n        :param domain: (optional) string containing domain of cookie\n        :param path: (optional) string containing path of cookie\n        :return: cookie.value\n        \"\"\"\n        for cookie in iter(self):\n            if cookie.name == name:\n                if domain is None or cookie.domain == domain:\n                    if path is None or cookie.path == path:\n                        return cookie.value\n\n        raise KeyError(f\"name={name!r}, domain={domain!r}, path={path!r}\")\n\n    def _find_no_duplicates(\n        self, name: str, domain: str | None = None, path: str | None = None\n    ) -> str:\n        \"\"\"Both ``__get_item__`` and ``get`` call this function: it's never\n        used elsewhere in Requests.\n\n        :param name: a string containing name of cookie\n        :param domain: (optional) string containing domain of cookie\n        :param path: (optional) string containing path of cookie\n        :raises KeyError: if cookie is not found\n        :raises CookieConflictError: if there are multiple cookies\n            that match name and optionally domain and path\n        :return: cookie.value\n        \"\"\"\n        toReturn = None\n        for cookie in iter(self):\n            if cookie.name == name:","sourceCodeStart":403,"sourceCodeEnd":439,"githubUrl":"https://github.com/psf/requests/blob/8068356288978c4f54661ae6f95afe0e0831885e/src/requests/cookies.py#L403-L439","documentation":"Raised by RequestsCookieJar.__getitem__ (via the cookie-lookup loop) when no cookie matches the requested name, and optionally the domain and path filters. The KeyError's string contains the exact name/domain/path triple queried so you can see which key was missing. It is the standard 'cookie not found' signal for jar lookups.","triggerScenarios":"Indexing a session.cookies jar with a cookie name that was never set (session.cookies['sid']) or was deleted/expired; passing domain= or path= kwargs to jar['name'] that do not match any stored cookie; looking up a cookie whose domain attribute differs (e.g. '.example.com' vs 'example.com').","commonSituations":"Trying to read a session cookie before the server has set it; cookie scoping differences (the jar stores domain/path-qualified entries, so the same name can exist under multiple scopes); relying on a cookie set on a subdomain but querying with the apex domain.","solutions":["Use session.cookies.get(name, default) or the get(name, domain=, path=) method instead of subscript access to avoid the KeyError.","Verify the cookie exists with name in jar or by iterating the jar before accessing.","Confirm domain/path filters match the server's Set-Cookie attributes exactly (including leading dot)."],"exampleFix":"// before\nvalue = session.cookies['sid']\n\n// after\nvalue = session.cookies.get('sid')\nif value is None:\n    # handle missing cookie\n    ...","handlingStrategy":"validation","validationCode":"from requests.cookies import RequestsCookieJar\n\ndef get_cookie_or_none(jar: RequestsCookieJar, name, domain=None, path=None):\n    # Use .get() instead of [] to avoid KeyError\n    return jar.get(name, domain=domain, path=path)","typeGuard":"from requests.cookies import RequestsCookieJar\n\ndef cookie_exists(jar: RequestsCookieJar, name, domain=None, path=None) -> bool:\n    for c in jar:\n        if c.name == name and (domain is None or c.domain == domain) and (path is None or c.path == path):\n            return True\n    return False","tryCatchPattern":"from requests.cookies import RequestsCookieJar\n\ntry:\n    value = session.cookies['sid']\nexcept KeyError as e:\n    # e.args[0] contains 'name=..., domain=..., path=...'\n    value = None","preventionTips":["Prefer session.cookies.get(name) over subscript access when absence is possible.","Check 'name' in session.cookies before indexing.","Match domain/path filters to the server's Set-Cookie attributes exactly."],"tags":["cookies","keyerror","cookiejar","lookup","http"],"backgroundTag":null,"analyzedSha":"8068356288978c4f54661ae6f95afe0e0831885e","analyzedAt":"2026-08-11T20:11:09.238Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}