question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reauthentication error

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:18

github_iconTop GitHub Comments

1reaction
Marnalascommented, Feb 16, 2022

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.

0reactions
alandtsecommented, Feb 16, 2022

I’ll see what I can do. So the integration does solely rely on the retrieved oauth token now and does not need the cookies and pickle file?

Are you not using the integration yourself anymore or just not interested in maintaining it further?

It still uses the pickle to save the cookies.

I use it but I’ve never had the auth problems. I just am spending my time on other interests. Again, if I had time, I would’ve removed the reauth path and removed legacy login options. They generate too many repeat issues.

Read more comments on GitHub >

github_iconTop Results From Across the Web

WiFi Authentication Errors and Methods to Solve Them - Okta
An authentication error occurs when a device can't connect to WiFi. Learn about what causes WiFi authentication problems and how to fix ...
Read more >
How to Fix WiFi Authentication Error Occurred on Android
This issue mostly means that your password for the network is wrong due to which it shows the authentication error message. You need...
Read more >
Authentication Error Occurred? -10 Proven Fixes - Dr.Fone
Authentication error occurs when the “deal” between the Wi-Fi router and device fails due to certain reasons. First, the device sends the password...
Read more >
5 Quick Methods To Solve WiFi Authentication Error in 2022
The most common solution for a WiFi authentication error or to fix authentication problem is to reset the WiFi connection in your network...
Read more >
5 Ways to Fix Wi-Fi Authentication Problems on Android
How to fix Wi-Fi authentication problems on Android · Toggle Airplane mode · Forget and reconnect to the Wi-Fi network · Reboot your...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found