Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

500 Internal Server Error - during Authentication after OTP confirmation #1765

Closed
dwetl opened this issue Oct 30, 2022 · 25 comments
Closed

500 Internal Server Error - during Authentication after OTP confirmation #1765

dwetl opened this issue Oct 30, 2022 · 25 comments

Comments

@dwetl
Copy link

dwetl commented Oct 30, 2022

Describe the bug
After confirmation OTP from Built-in 2FA App Key confirmed successfully the next page is loading successfully.
Entering email and PWD and clicking the login in button gives the following error:

500 Internal Server Error
Server got itself in trouble

To Reproduce
see above

Expected behavior

Screenshots
image

image

System details

  • Home-assistant (version): 2022.9.6
    Frontend 20220907.2 - latest
  • alexa_media: 4.2.0
  • alexapy: 1.26.4
  • Amazon 2FA is enabled (y/n). yes

Logs
This error originated from a custom integration.

Logger: aiohttp.server
Source: custom_components/alexa_media/config_flow.py:881
Integration: alexa_media (documentation, issues)
First occurred: 3:10:01 PM (1 occurrences)
Last logged: 3:10:01 PM

Error handling request
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/anyio/streams/tls.py", line 130, in _call_sslobject_method
result = func(*args)
File "/usr/local/lib/python3.10/ssl.py", line 917, in read
v = self._sslobj.read(len)
ssl.SSLWantReadError: The operation did not complete (read) (_ssl.c:2548)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/httpcore/backends/asyncio.py", line 33, in read
return await self._stream.receive(max_bytes=max_bytes)
File "/usr/local/lib/python3.10/site-packages/anyio/streams/tls.py", line 195, in receive
data = await self._call_sslobject_method(self._ssl_object.read, max_bytes)
File "/usr/local/lib/python3.10/site-packages/anyio/streams/tls.py", line 137, in _call_sslobject_method
data = await self.transport_stream.receive()
File "/usr/local/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 1265, in receive
await self._protocol.read_event.wait()
File "/usr/local/lib/python3.10/asyncio/locks.py", line 214, in wait
await fut
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/httpcore/_exceptions.py", line 8, in map_exceptions
yield
File "/usr/local/lib/python3.10/site-packages/httpcore/backends/asyncio.py", line 31, in read
with anyio.fail_after(timeout):
File "/usr/local/lib/python3.10/site-packages/anyio/_core/_tasks.py", line 118, in exit
raise TimeoutError
TimeoutError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/httpx/_transports/default.py", line 60, in map_httpcore_exceptions
yield
File "/usr/local/lib/python3.10/site-packages/httpx/_transports/default.py", line 353, in handle_async_request
resp = await self._pool.handle_async_request(req)
File "/usr/local/lib/python3.10/site-packages/httpcore/_async/connection_pool.py", line 253, in handle_async_request
raise exc
File "/usr/local/lib/python3.10/site-packages/httpcore/_async/connection_pool.py", line 237, in handle_async_request
response = await connection.handle_async_request(request)
File "/usr/local/lib/python3.10/site-packages/httpcore/_async/connection.py", line 90, in handle_async_request
return await self._connection.handle_async_request(request)
File "/usr/local/lib/python3.10/site-packages/httpcore/_async/http11.py", line 105, in handle_async_request
raise exc
File "/usr/local/lib/python3.10/site-packages/httpcore/_async/http11.py", line 84, in handle_async_request
) = await self._receive_response_headers(**kwargs)
File "/usr/local/lib/python3.10/site-packages/httpcore/_async/http11.py", line 148, in _receive_response_headers
event = await self._receive_event(timeout=timeout)
File "/usr/local/lib/python3.10/site-packages/httpcore/_async/http11.py", line 177, in _receive_event
data = await self._network_stream.read(
File "/usr/local/lib/python3.10/site-packages/httpcore/backends/asyncio.py", line 30, in read
with map_exceptions(exc_map):
File "/usr/local/lib/python3.10/contextlib.py", line 153, in exit
self.gen.throw(typ, value, traceback)
File "/usr/local/lib/python3.10/site-packages/httpcore/_exceptions.py", line 12, in map_exceptions
raise to_exc(exc)
httpcore.ReadTimeout

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

Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 435, in _handle_request
resp = await request_handler(request)
File "/usr/local/lib/python3.10/site-packages/aiohttp/web_app.py", line 504, in _handle
resp = await handler(request)
File "/usr/local/lib/python3.10/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 222, 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 82, in ban_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 236, in auth_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 136, in handle
result = await result
File "/config/custom_components/alexa_media/config_flow.py", line 881, in wrapped
return await cls.handler(request, **kwargs)
File "/usr/local/lib/python3.10/site-packages/authcaptureproxy/auth_capture_proxy.py", line 375, in all_handler
resp = await getattr(self.session, method)(
File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1842, in post
return await self.request(
File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1527, in request
return await self.send(request, auth=auth, follow_redirects=follow_redirects)
File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1614, in send
response = await self._send_handling_auth(
File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1642, in _send_handling_auth
response = await self._send_handling_redirects(
File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1679, in _send_handling_redirects
response = await self._send_single_request(request)
File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1716, in _send_single_request
response = await transport.handle_async_request(request)
File "/usr/local/lib/python3.10/site-packages/httpx/_transports/default.py", line 352, in handle_async_request
with map_httpcore_exceptions():
File "/usr/local/lib/python3.10/contextlib.py", line 153, in exit
self.gen.throw(typ, value, traceback)
File "/usr/local/lib/python3.10/site-packages/httpx/_transports/default.py", line 77, in map_httpcore_exceptions
raise mapped_exc(message) from exc
httpx.ReadTimeout

@alandtse
Copy link
Owner

Please provide logs per the FAQ. I only need the last step when you submit. Please note you'll need to scrub your username/password.

https://github.com/custom-components/alexa_media_player/wiki/FAQ#how-do-i-enable-debug-logging-for-the-component

@dwetl
Copy link
Author

dwetl commented Nov 1, 2022 via email

@randomevents
Copy link

Seeing the same issue

@Sly8383
Copy link

Sly8383 commented Nov 8, 2022

Hi guys,
I had the same issue with my integration.
I don't understand exactly the reason but it seems because of my domain name was not completly reachable from my internal network.
For me the solution was to perform the integration from external network.

I hope it will help

@dwetl
Copy link
Author

dwetl commented Nov 11, 2022

Tried to export all log now.. pls check if anything is missing.
error.log

@dwetl
Copy link
Author

dwetl commented Nov 11, 2022

Hi guys, I had the same issue with my integration. I don't understand exactly the reason but it seems because of my domain name was not completly reachable from my internal network. For me the solution was to perform the integration from external network.

I hope it will help

tried as well, was not working for me, same error. but thanks for letting me know :)

@dwetl
Copy link
Author

dwetl commented Nov 13, 2022

now it seems when i restart HA i get a notification with an OTP?

@elessar2004
Copy link

elessar2004 commented Nov 15, 2022

I have the same issue with the Alexa integration. I'm stuck at the 500 Internal error page and have a pretty similar (identical?) error log. I have tried everything I know with no luck :(.

Edit: I tried from outside my network as suggested by Sly8383 and the error changed to "401: unauthorized" after a new captcha (image to write the letters instead of the username and password) from Amazon. The log shows:

Login attempt or request with invalid authentication from 86-127-239-165.digimobil.es (86.127.239.165). Requested URL: '/auth/alexamedia/proxy/ap/signin/135-6868654-0138912'. (Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36)
Login attempt or request with invalid authentication from 86-127-239-165.digimobil.es (86.127.239.165). Requested URL: '/auth/alexamedia/proxy/errors/validateCaptcha?amzn=qh2KUB3zDpLXxCuXnPRAXw%3D%3D&amzn-r=/ap/signin?openid.return_to%3Dhttps://www.amazon.com/ap/maplanding%26openid.assoc_handle%3Damzn_dp_project_dee_ios%26openid.identity%3Dhttp://specs.openid.net/auth/2.0/identifier_select%26pageId%3Damzn_dp_project_dee_ios%26accountStatusPolicy%3DP1%26openid.claimed_id%3Dhttp://specs.openid.net/auth/2.0/identifier_select%26openid.mode%3Dcheckid_setup%26openid.ns.oa2%3Dhttp://www.amazon.com/ap/ext/oauth/2%26openid.oa2.client_id%3Ddevice:336538393534303932333366326139636662376536303065363833653563346523413249564c5635564d32573831%26openid.ns.pape%3Dhttp://specs.openid.net/extensions/pape/1.0%26openid.oa2.response_type%3Dtoken%26openid.ns%3Dhttp://specs.openid.net/auth/2.0%26openid.pape.max_auth_age%3D0%26openid.oa2.scope%3Ddevice_auth_access%26language%3Des_ES&amzn-pt=AuthenticationPortal&field-keywords=ccljkx'. (Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36)

This makes me feel I'm doing something wrong when filling the setup page...

@Barry-Ricoh
Copy link

Internal and external i got the Same error.

@Finne75
Copy link

Finne75 commented Jan 8, 2023

I have the same issue of an 500 Internal Server Error coming up after the Amazon Alexa login page. I use an nginx reverse proxy (on another machine), not sure whether this relates to the problem or not. Some time ago, the integration still worked but stopped doing so (not recently). I tried the setup procedure both from internal and external (via VPN), no difference in outcome or behaviour.

I put some logs here.

@poulti
Copy link

poulti commented Jan 9, 2023

Hello,
Has been working fine until I changed my Amazon password and had to reconfigure the integration. I'm now having the same issue and same logs as @Finne75. I’m using v4.4.0 of Alexa Media Player. Home Assistant 2023.1.1. My config is accessible from internet (nginx+letsencrypt certs) etc.

Error logs: (the OTP is correct and same as my phone btw)
home-assistant_2023-01-10T19-26-45.810Z.log

@poulti
Copy link

poulti commented Jan 12, 2023

Updated to 4.5.0 this morning and Home Assistant 2023.1.2, still same Error 500 after the authentication form.

Error logs:
home-assistant_2023-01-12T08-44-25.269Z.log

@alandtse
Copy link
Owner

If you have IPv6 enabled in HA, try disabling. Odd network errors like you all seem to be seeing may be linked to that setting. You can reenabled after authenticating fully.

@elessar2004
Copy link

Hello,
Unfortunately, disabling IPv6 does not solve the issue. From an external network, I still get the 401 unauthorized error. I will try from the internal network but I will probably receive again the 501 internal server error.

Thanks in any case.

@poulti
Copy link

poulti commented Jan 13, 2023

Hello,
No luck with IPv6 either - I turned it off at the network adapter level, still same behaviour.
Any workaround in the meantime?

@Finne75
Copy link

Finne75 commented Jan 13, 2023

Same here, IPv6 is disabled already since long time.

@cvladan
Copy link

cvladan commented Jan 13, 2023

I solved this problem by trying to create another bug ticket and while doing so, I stumbled upon the solution! Please, don't make me type it all over again, I've already posted all the juicy details on link here. Ta-da! 🎉

So go ahead and give it a try yourself - maybe it will solve your problem too!

@poulti
Copy link

poulti commented Jan 13, 2023

I solved this problem by trying to create another bug ticket and while doing so, I stumbled upon the solution! Please, don't make me type it all over again, I've already posted all the juicy details on link here. Ta-da! 🎉

So go ahead and give it a try yourself - maybe it will solve your problem too!

You got my hopes up!
Unfortunately, I tried this by adding alexapy inside the hass container - same result and stack trace leading to error 500.

Edit: actually it worked - the key difference was to use the internal IP:PORT not the external one.
Thank you @cvladan

@elessar2004
Copy link

Thank you cvladan, after doing as you said now it works!!
Best

@cvladan
Copy link

cvladan commented Jan 15, 2023

I solved this problem by trying to create another bug ticket and while doing so, I stumbled upon the solution! Please, don't make me type it all over again, I've already posted all the juicy details on link here. Ta-da! 🎉
So go ahead and give it a try yourself - maybe it will solve your problem too!

You got my hopes up! Unfortunately, I tried this by adding alexapy inside the hass container - same result and stack trace leading to error 500.

Edit: actually it worked - the key difference was to use the internal IP:PORT not the external one. Thank you @cvladan

Yes! I was able to solve the problem by doing both of the following two steps:

  1. Installing the Python library manually using pip install alexapy
  2. Using the internal HA address instead of the external one

@cvladan
Copy link

cvladan commented Jan 15, 2023

I would like to direct attention to this thread, as the comments there are also noteworthy - #1825

@dwetl dwetl closed this as completed Jan 18, 2023
@LucaF87
Copy link

LucaF87 commented Feb 9, 2023

Hi,
I followed all your advice but without success, as soon as I sign in it gives me ERROR 500

@joshstewart
Copy link

joshstewart commented Feb 9, 2023

Using the Terminal & SSH add-on, when I run pip install alexapy, all I get is:

bash: pip: command not found

@cvladan
Copy link

cvladan commented Feb 9, 2023

Using the Terminal & SSH add-on, when I run pip install alexapy, all I get is:

bash: pip: command not found

Maybe pip3 install alexapy ? There is FAQ about it.

@joshstewart
Copy link

joshstewart commented Feb 9, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests