Kane610 / aiounifi

Asynchronous library to communicate with Unifi Controller
MIT License
60 stars 53 forks source link

Recommendation re: recent addition to connectivity.py to address partitioned cookies #728

Open danielbrunt57 opened 1 week ago

danielbrunt57 commented 1 week ago

I saw your fix for the partitioned cookie error in python 3.12 cookies.py and have implemented a variation of this into the alexapy python package thus resolving a 3 month old issue. Your code is version restricted though and I believe the partitioned "key : value" pair isn't going to make it into Python 3.13 cookies.py Morsel class which would then break your code again. My variation is version non-specific and uses _reserved.update which only adds the "key : value" pair if it does not exist and does nothing if it's already there. The _flags.add already behaves that way so it's fine. alexalogin.py:

`from http.cookies import Morsel, SimpleCookie`
"""Ensure cookies.Morsel contains "partitioned"
   See: https://github.com/python/cpython/issues/112713
"""
partitioned = { "partitioned" : "Partitioned" }
Morsel._reserved.update(partitioned)
Morsel._flags.add("partitioned")
_LOGGER.debug("http.cookies patch: Morsel._reserved: %s; Morsel._flags: %s", partitioned, Morsel._flags)

I had to alter my implementation of your code as alexalogin.py was already using a variable named cookies thus preventing me from importing cookies from http.

Kane610 commented 4 days ago

Thanks! All kudos goes to ep1cman in https://github.com/uilibs/uiprotect/pull/36 that I took the changes from.

I'll wait some before I do this change