{"record":{"id":"0e62d2f5b65c53f9","repo":"psf/requests","slug":"there-are-multiple-cookies-with-name-name-r","errorCode":null,"errorMessage":"There are multiple cookies with name, {name!r}","messagePattern":"There are multiple cookies with name, (.+?)","errorType":"exception","errorClass":"CookieConflictError","httpStatus":null,"severity":"error","filePath":"src/requests/cookies.py","lineNumber":444,"sourceCode":"        \"\"\"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:\n                if domain is None or cookie.domain == domain:\n                    if path is None or cookie.path == path:\n                        if toReturn is not None:\n                            # if there are multiple cookies that meet passed in criteria\n                            raise CookieConflictError(\n                                f\"There are multiple cookies with name, {name!r}\"\n                            )\n                        # we will eventually return this as long as no cookie conflict\n                        toReturn = cookie.value\n\n        if toReturn is not None:\n            return toReturn\n        raise KeyError(f\"name={name!r}, domain={domain!r}, path={path!r}\")\n\n    def __getstate__(self) -> dict[str, Any]:\n        \"\"\"Unlike a normal CookieJar, this class is pickleable.\"\"\"\n        state = self.__dict__.copy()\n        # remove the unpickleable RLock object\n        state.pop(\"_cookies_lock\")\n        return state\n\n    def __setstate__(self, state: dict[str, Any]) -> None:\n        \"\"\"Unlike a normal CookieJar, this class is pickleable.\"\"\"","sourceCodeStart":426,"sourceCodeEnd":462,"githubUrl":"https://github.com/psf/requests/blob/8068356288978c4f54661ae6f95afe0e0831885e/src/requests/cookies.py#L426-L462","documentation":"Raised by RequestsCookieJar._find_no_duplicates when two or more stored cookies share the same name (and match the optional domain/path filters). Because subscript access (__getitem__) cannot disambiguate which value to return, requests refuses with CookieConflictError. This is a data-integrity guard, not a normal control-flow path.","triggerScenarios":"A server sets two Set-Cookie headers with the same name but different domains or paths (e.g. one for '/' and one for '/app'), and the caller does jar['name']; manually merging jars that contain overlapping names; using set() without specifying domain/path while duplicate names already exist.","commonSituations":"Login flows that issue a fresh token cookie on '/' while an old one persists on a subpath; third-party SSO cookies colliding with first-party names; cross-domain cookies with identical names stored in one jar.","solutions":["Disambiguate by supplying domain= and path= to _find_no_duplicates via jar.get(name, domain=, path=) or clear_specific() to target one.","Remove the stale duplicate with session.cookies.clear(domain=..., path=...) before re-issuing.","Use jar.iter_cookies() (or iterate the jar) to enumerate all matches and pick the intended one."],"exampleFix":"// before\nvalue = session.cookies['sid']\n\n// after\nvalue = session.cookies.get('sid', domain='example.com', path='/')","handlingStrategy":"validation","validationCode":"from requests.cookies import RequestsCookieJar, CookieConflictError\n\ndef get_unique_cookie(jar, name, domain=None, path=None, default=None):\n    matches = [c for c in jar if c.name == name\n               and (domain is None or c.domain == domain)\n               and (path is None or c.path == path)]\n    if len(matches) == 0:\n        return default\n    if len(matches) > 1:\n        raise CookieConflictError(f\"multiple cookies named {name!r}; disambiguate via domain/path\")\n    return matches[0].value","typeGuard":"from requests.cookies import RequestsCookieJar\n\ndef is_unique(jar: RequestsCookieJar, name, domain=None, path=None) -> bool:\n    count = 0\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            count += 1\n            if count > 1:\n                return False\n    return count == 1","tryCatchPattern":"from requests.cookies import CookieConflictError\n\ntry:\n    value = session.cookies['sid']\nexcept CookieConflictError:\n    value = session.cookies.get('sid', domain='example.com', path='/')","preventionTips":["Always specify domain= and path= when querying jars that may contain scoped duplicates.","Clear stale cookies before re-issuing login tokens (session.cookies.clear(domain=..., path=...)).","Audit multi-domain login flows that reuse the same cookie name."],"tags":["cookies","cookieconflict","cookiejar","duplicate","http"],"backgroundTag":null,"analyzedSha":"8068356288978c4f54661ae6f95afe0e0831885e","analyzedAt":"2026-08-11T20:11:09.238Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}