Troubleshooting rabbithole of the day:

  • My Unifi Protect metrics exporter no longer works because it crashes on a KeyError
  • The KeyError is actually an unhandled auth error, oops.
  • The auth just fails with no further details. Added plenty more debugging and turns out the #aiohttp session object cookie jar is empty, no auth for me.
  • The Set-Cookie header on the POST call response does have the right token, so login works! But the response cookies is empty, so is the session cookie jar. Hrmph!
  • Figure out behind the scenes it loads the header raw into a http.cookies.SimpleCookie, which when manually replicating indeed silently without error just doesn't load the data! Not great.
  • Turns out it balks if the cookie contains a partitioned argument, just refuses silently to load the cookie.

[1/2]

  • SimpleCookie is a Python built-in, and it seems they delayed adding support for partitioned since it's not yet standard, but #Chrome just does Chrome things and pushed it on the world anyway, so now Protect "needs" to include it to work in Chrome.
  • So now I get to do text manipulation on cookie headers just so I can strip the unsupported option and get the auth token into the session!

Why is technology so shit.

[2/2]