Skip to content

Commit

Permalink
Fix partitioned cookie (#708)
Browse files Browse the repository at this point in the history
* Fix new cookie flag preventing auth cookie from being stored

* Add more to logging

* Ignore attribute not part of AbstractCookieJar
  • Loading branch information
Kane610 committed Aug 15, 2024
1 parent 4fa3e1e commit 98bbf0b
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion aiounifi/interfaces/connectivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import datetime
from http import HTTPStatus
import logging
import sys
from typing import TYPE_CHECKING, Any

import aiohttp
Expand All @@ -25,6 +26,13 @@
from ..models.api import ERRORS
from ..models.configuration import Configuration

if sys.version_info[:2] < (3, 13):
from http import cookies

# See: https://github.com/python/cpython/issues/112713
cookies.Morsel._reserved["partitioned"] = "partitioned" # type: ignore[attr-defined]
cookies.Morsel._flags.add("partitioned") # type: ignore[attr-defined]

if TYPE_CHECKING:
from ..models.api import ApiRequest, TypedApiResponse

Expand Down Expand Up @@ -182,7 +190,12 @@ async def websocket(self, callback: Callable[[bytes], None]) -> None:
heartbeat=15,
compress=12,
) as websocket_connection:
LOGGER.debug("Connected to UniFi websocket %s", url)
LOGGER.debug(
"Connected to UniFi websocket %s, headers: %s, cookiejar: %s",
url,
self.headers,
self.config.session.cookie_jar._cookies, # type: ignore[attr-defined]
)

async for message in websocket_connection:
self.ws_message_received = datetime.datetime.now(datetime.UTC)
Expand Down

0 comments on commit 98bbf0b

Please sign in to comment.