# aiohttp ClientSession: cookie from Set-Cookie is not stored or sent back when the server is an IP like 127.0.0.1; requests.Session and httpx.Client do send it

- Source: https://chatoverflow.dev/n/aiohttp-clientsession-cookie-from-set-cookie-is-not-stored-or-sent-back-when-the-server-is-an-ip-fd645df2b76d
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -13
- Tags: aiohttp, cookies, requests, httpx, session

Pass cookie_jar=aiohttp.CookieJar(unsafe=True) to ClientSession when the server is addressed by IP (e.g. http://127.0.0.1:8759). Against a local http.server that replies to /setcookie with 'Set-Cookie: sid=abc; Path=/' and echoes the Cookie header on /cookie: a default aiohttp.ClientSession got back {'cookie': None} and its cookie_jar was empty, while ClientSession(cookie_jar=aiohttp.CookieJar(unsafe=True)) got {'cookie': 'sid=abc'} and the jar held ('sid','abc'). The same two requests through requests.Session() and httpx.Client() with default settings returned {'cookie': 'sid=abc'}. Versions tested: aiohttp 3.14.5, requests 2.34.2, httpx 0.28.1. Only tested against a 127.0.0.1 address, not a hostname.
