alexa_media_player: Reauthentication error

Describe the bug Reauthentication is impossible. Opening the Amazon website from the addon will show an error. It seems to be related to the cookiejar conversion between aiohttp and httpx. Only way to get it going again is removing the integration and setting it up again.

To Reproduce Steps to reproduce the behavior:

  1. Reauthenticate

Expected behavior

Screenshots

System details

  • Home-assistant (version): latest
  • Hassio (Yes/No): (Please note you may have to restart hassio 2-3 times to load the latest version of alexapy after an update. This looks like a HA bug).
  • alexa_media (version from const.py or HA startup): 3.10.15
  • alexapy (version from pip show alexapy or HA startup): 1.25.3 (authcaptureproxy 1.1.1)
  • Amazon 2FA is enabled (y/n). We will not debug login issues if unanswered: yes

Logs

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_protocol.py", line 435, in _handle_request
    resp = await request_handler(request)
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 60, in security_filter_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 220, in forwarded_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 79, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 219, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 137, in handle
    result = await result
  File "/config/custom_components/alexa_media/config_flow.py", line 1122, in wrapped
    return await cls.handler(request, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/authcaptureproxy/auth_capture_proxy.py", line 387, in all_handler
    resp = await getattr(self.session, method)(
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1736, in get
    return await self.request(
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1500, in request
    request = self.build_request(
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 351, in build_request
    return Request(
  File "/usr/local/lib/python3.9/site-packages/httpx/_models.py", line 1099, in __init__
    Cookies(cookies).set_cookie_header(self)
  File "/usr/local/lib/python3.9/site-packages/httpx/_models.py", line 1792, in set_cookie_header
    self.jar.add_cookie_header(urllib_request)
  File "/usr/local/lib/python3.9/http/cookiejar.py", line 1367, in add_cookie_header
    attrs = self._cookie_attrs(cookies)
  File "/usr/local/lib/python3.9/http/cookiejar.py", line 1326, in _cookie_attrs
    self.non_word_re.search(cookie.value) and version > 0):
TypeError: expected string or bytes-like object

Additional context

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 18 (9 by maintainers)

Commits related to this issue

Most upvoted comments

In case it helps someone.

I had the exact same problem you describe @larena1 (exact same logs and similar system details). I tried what you proposed and had, again, the exact same result Multiple cookies exist with name=session-id.

            cookies = self.login._session.cookie_jar.filter_cookies(
                self.proxy._host_url.with_path("/")
            )
            cookies = {k: v.value for k, v in cookies.items()}
            self.proxy.session.cookies = cookies

While investigating I found out that I had a remnant of a precious version in my configuration.yaml I had completly forgotten about :

alexa_media:
  accounts:
    - email: !secret amazon_user
      password: !secret amazon_password
      url: amazon.com

I then did this:

  1. I removed this configuration ;
  2. I restarted HomeAssistant ;
  3. I removed the HACS integration ;
  4. I added the HACS integration again (3.10.15) ;
  5. I restarted HomeAssistant ;
  6. I added the integration and configured it following the standard way (didn’t touch any checkbox). It then worked on the first try.

@alandtse thank you for your work. I enjoy it a great deal.