alexa_media_player: 500 Internal Server Error Server got itself in trouble

Describe the bug At the end of the configuration, after entering the capcha the error appears: 500 Internal Server Error Server got itself in trouble

To Reproduce

  1. Go to Settings
  2. Click on Devices & Services
  3. Scroll down to Alexa Media Player
  4. Configure until capcha solved

System details

HA: Core 2024.7.3 Supervisor 2024.06.2 Operating System 12.4 Frontend 20240710.0

Integration: alexa_media_player: 4.11.4

Logs

2024-07-21 12:16:08.741 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/httpx/_transports/default.py", line 69, in map_httpcore_exceptions
    yield
  File "/usr/local/lib/python3.12/site-packages/httpx/_transports/default.py", line 373, in handle_async_request
    resp = await self._pool.handle_async_request(req)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/httpcore/_async/connection_pool.py", line 216, in handle_async_request
    raise exc from None
  File "/usr/local/lib/python3.12/site-packages/httpcore/_async/connection_pool.py", line 196, in handle_async_request
    response = await connection.handle_async_request(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/httpcore/_async/connection.py", line 101, in handle_async_request
    return await self._connection.handle_async_request(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/httpcore/_async/http11.py", line 143, in handle_async_request
    raise exc
  File "/usr/local/lib/python3.12/site-packages/httpcore/_async/http11.py", line 113, in handle_async_request
    ) = await self._receive_response_headers(**kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/httpcore/_async/http11.py", line 186, in _receive_response_headers
    event = await self._receive_event(timeout=timeout)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/httpcore/_async/http11.py", line 224, in _receive_event
    data = await self._network_stream.read(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/httpcore/_backends/anyio.py", line 32, in read
    with map_exceptions(exc_map):
  File "/usr/local/lib/python3.12/contextlib.py", line 158, in __exit__
    self.gen.throw(value)
  File "/usr/local/lib/python3.12/site-packages/httpcore/_exceptions.py", line 14, in map_exceptions
    raise to_exc(exc) from exc
httpcore.ReadTimeout

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_protocol.py", line 452, in _handle_request
    resp = await request_handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_app.py", line 543, in _handle
    resp = await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_middlewares.py", line 114, in impl
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 92, in security_filter_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 83, in forwarded_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 26, in request_context_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 242, in auth_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 32, in headers_middleware
    response = await handler(request)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/http.py", line 73, in handle
    result = await handler(request, **request.match_info)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/alexa_media/config_flow.py", line 1001, in wrapped
    return await cls.handler(request, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/authcaptureproxy/auth_capture_proxy.py", line 439, in all_handler
    resp = await getattr(self.session, method)(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/httpx/_client.py", line 1892, in post
    return await self.request(
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/httpx/_client.py", line 1574, in request
    return await self.send(request, auth=auth, follow_redirects=follow_redirects)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/httpx/_client.py", line 1661, in send
    response = await self._send_handling_auth(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/httpx/_client.py", line 1689, in _send_handling_auth
    response = await self._send_handling_redirects(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/httpx/_client.py", line 1726, in _send_handling_redirects
    response = await self._send_single_request(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/httpx/_client.py", line 1763, in _send_single_request
    response = await transport.handle_async_request(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/httpx/_transports/default.py", line 372, in handle_async_request
    with map_httpcore_exceptions():
  File "/usr/local/lib/python3.12/contextlib.py", line 158, in __exit__
    self.gen.throw(value)
  File "/usr/local/lib/python3.12/site-packages/httpx/_transports/default.py", line 86, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.ReadTimeout

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 77

Most upvoted comments

Hi DeekB1983

Can you open a browser and try accessing your home assistant server using http://homeassistant.local:8123

No Yes via duckdns and lanIP

Not sure what that means for the issue we have at the moment sadly, I also couldnt access homeassistant.local but have changed my config slightly and I can now but I still have the samne issue with httpx.ReadTimeout and not sure why thats now happening. Temped to restore an earlier back up to see if it resolves the issue as that would confirm its down to one of the later updates but its a lot of work to do that.

Now that I know better, the actual HA URL you stipulate in the config setup is irrelevant as long as that URL can reach the homeassistant login window from your local browser as it’s there that the callback using the base URL is made. Initially, I did not fully understand what was actually happening at that point. The browser is reaching out to amazon triggering it’s login process but the callback URL is not from Amazon to HA as I was mistakenly thinking at the beginning of all this, it’s just from the local browser to HA.

Since there is an httpx read timeout that Alan at one point alluded to being IPv6 related, and since I have IPv6 configured and working in my network, perhaps it is an issue inside core when IPv6 is disabled, or it’s enabled but not really working internally. Since HA allows you to disable IPv6, it should be able to handle it, meaning it would be a core issue. That said, I do not have proof yet that a disabled IPv6 is the reason, I’m just trying to figure out in my head where the issue lies. It could also be related to docker vs non-docker setup. Still guessing though…

I have IPv6 enabled and set to auto:

image

My PC network settings: image

My pfSense firewall settings:

image image

And I can use the IPv6 address to get to HA login window: http://[fd12:3456:789a:1::68]:8123 image

But I still don’t know if that is relevant or not…

I managed to get the Alexa Media Player app set up again just now on the latest HA software and latest Alexa Media player app, it seems I made a monumetal mistake my end and I apologize for that, let me explain below what I think happened.

When I originally had the issue after updates 3- 4 days ago I came on here for support, 2 days ago during troublehsooting I went into the amazon web page as I had ticked the dont require OTP on this browser on a few of the systems I use at home (at the time I didnt realise this would be a problem but after some of Daniels posts it made me realise how it is working), during this time I disabled 2FA to try and see if it would make any difference (It didnt as using 2FA is a requirement for this app) I mentioned I had disabled 2FA in this comment - https://github.com/alandtse/alexa_media_player/issues/2347#issuecomment-2242751303

it seems I never re-enabled 2FA properly after disabling it (this is the biggest miskate ever, I had scanned the code and entered the 6 digit 2FA code but I didnt go to page 2 and confirm it) if you disable and set up 2FA again on your amazon account you will see what I mean by this comment of having to go to page 2 to confirm it, I only noticed this tonight when I cleared my browser cache again (I cleared the browser cache many times over the last few days) what prompted me to noticed 2FA was disabled this time is when I went to log back into Amazon I wasnt asked to enter a 2FA code when I should have been as I had reset the following options for surpessing of OTP the other day around the same time I disabled it, as I said above I wasnt aware supressing 2FA on the browser would cause this issue but it became clear to me after Daniels explaination on how its working in his comment above today, also the fact I left 2FA in a disabled state by accident thinking I had re-enabled it but I didnt (So all the testing and stuff I completed with restoring backups is null in void becuase 2FA is a requirement for this app setup to work and it was not set up during all of that testing and I only discovered that tonight) image

I then went into my login settings within my amazon account tonight and discovered it was still disabled from 2 days ago, after re-enabling it and going through the 2 pages of prompts I then got the following screen when setting up the integration. image

I have a feeling this issue was happening for me as I was surpressing the OPT code at the broswer level for my amazon account intially and I then continued to have issues after clearing the surpression as I disabled 2FA and thought I had re-enabled it but hadnt fully confirmed it as I said above (stupid stupid mistake my end)

Thank you for the help Daniel and sorry for any time you have wasted trying to help me with my problem even although the problem was not derived from code like I thought as it happened after an update, it was completely a user error on my part.

For other users I suggest the following:

  • Ensure you can log into Amazon.co.uk with the correct details. (Or whatever domain for the country you are in)
  • Confirm 2FA is set up properly for your amazon account
  • Ensure you are not supressing the use of the OTP on the browser you are trying to register the app from
  • Ensure you use the correct username, password , OTP & Domain during set up of the app within home assistant

I feel very silly after all of this and can only apologize to Daniel as I feel I waste his time, I can only hope that this information also helps other people out with the issues they have too!

Make sure 2FA OTP is enabled for your Amazon account. Make sure you haven’t previously checked the box Don't require OTP on this browser when you’ve been logging into https://amazon.com` (or whatever domain your account is in). If you have then try clearing then via Require OTP on all devices in Amazon > Your account > Login and security > Two-Step Verification (2SV) Settings

I believe this issue is now resolved then.
If nobody has any objections, I’d like to request it be closed…

It’s the only logical explaination I can come up with that I had it surpressed, thats not known its just an assumption as I see no other reason as 2FA was enabled on my account for a long time untill 2 days ago! I am also glad I found it and as I said I hope these posts help someone else.

It is also strange as during updates a few weeks ago I was asked to reauthenticate Alexa Media Playerand it worked without an issue, it only started failing after the most recent updates which is strange, I still dont fully understand why I was getting the capchta to begin with, I can only assume it was down to the supression on devices and then I made the problem permanent by disabling 2FA, I have +30 accounts where 2FA is set up and I also use a Yubikey for authetication for some things as I am very security concious, you need to be in todays world.

BTW, and FWIW, my browser always prompts for OTP when I log into Amazon no matter how many damns I’ve clicked the Don’t require OTP on this browser!

I think clearing the devices registered for OTP suppression in Amazon would be sufficient but then again, I can’t test that as it’s never worked reliably for me at any time!

image

I feel very silly after all of this and can only apologize to Daniel as I feel I waste his time, I can only hope that this information also helps other people out with the issues they have too!

Hey, there’s no need to apologize! Things like this keep me constantly thinking and maybe that might help defer Alzheimer’s! I’m just glad it’s finally figured out so, thank you for finally finding the reason no mater how silly or stupid! We’re all human! Plus having worked all these years in IT support, I’m used to problems that ended up being a PEBKAC! I and others I’ve worked alongside have completed many support tickets where the internal resolution note was simply “PEBKAC”…

OMG, thank you! I am up and running now too. The key is even though Amazon allows you to add an authenticator app, you need to actually go to Your Account > Account > Login & Security > and “Turn on 2FA”!