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

TypeError: can only concatenate str (not "NoneType") to str #2515

Closed
Kalfany opened this issue Sep 9, 2024 · 77 comments
Closed

TypeError: can only concatenate str (not "NoneType") to str #2515

Kalfany opened this issue Sep 9, 2024 · 77 comments

Comments

@Kalfany
Copy link

Kalfany commented Sep 9, 2024

Describe the bug

The integration no longer starts. In the past, multiple restarts helped (HA 2024.07 / HA 2024.08), but recently, nothing helps anymore. A complete reinstallation worked for 2 days, but after several restarts, the same problem occurred again.

Same or similar to #1072

TypeError: can only concatenate str (not "NoneType") to str

Logger: homeassistant.config_entries
Source: config_entries.py:604
First occurred: 11:43:46 (2 occurrences)
Last logged: 12:03:05

Error setting up entry xxx@xxx.de - amazon.de for alexa_media
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 604, in async_setup
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/alexa_media/__init__.py", line 361, in async_setup_entry
    await login.login(cookies=await login.load_cookie())
  File "/usr/local/lib/python3.12/site-packages/alexapy/helpers.py", line 137, in wrapper
    return await func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/alexapy/alexalogin.py", line 703, in login
    self._site = await self._process_page(await post_resp.text(), site)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/alexapy/alexalogin.py", line 1463, in _process_page
    error_message += list_item.find("span").string
TypeError: can only concatenate str (not "NoneType") to str

To Reproduce

🤷‍♂️

Expected behavior

Screenshots
image

System details

  • Home Assistant version: 2024.9.1
  • alexa_media version (from const.py or HA startup log): 4.12.12
  • alexapy version (from pip show alexapy in homeasssistant container or HA startup log): 1.28.2
  • Is Amazon 2FA/2SV enabled <!---We will not debug login issues if unanswered---> (y/n): y
  • Amazon Domain: amazon.de

Debug Logs (alexa_media & alexapy)
Please provide logs.


2024-09-09 12:25:09.110 DEBUG (MainThread) [custom_components.alexa_media] Nothing to import from configuration.yaml, loading from Integrations
2024-09-09 12:25:09.110 DEBUG (MainThread) [custom_components.alexa_media] 
-------------------------------------------------------------------
alexa_media
Version: 4.12.12
This is a custom component
If you have any issues with this you need to open an issue here:
https://github.com/alandtse/alexa_media_player/issues
-------------------------------------------------------------------
2024-09-09 12:25:09.110 DEBUG (MainThread) [custom_components.alexa_media] Loaded alexapy==1.28.2
2024-09-09 12:25:09.111 DEBUG (MainThread) [custom_components.alexa_media.helpers] XXXXXXXXXXXX: Returning uuid {'uuid': 'e4bb66b28ad9b65ee8bb459f315da469', 'index': 0}
2024-09-09 12:25:09.161 DEBUG (MainThread) [alexapy.alexalogin] Creating TOTP for XXXXXXXXXXXX
2024-09-09 12:25:09.161 DEBUG (MainThread) [alexapy.alexalogin] Generating OTP XXXXXXXXXXXX
2024-09-09 12:25:09.166 DEBUG (MainThread) [alexapy.alexalogin] Login created for XXXXXXXXXXXX - amazon.de
2024-09-09 12:25:09.172 DEBUG (MainThread) [alexapy.alexalogin] Searching for cookies from /config/.storage/alexa_media.XXXXXXXXXXXX.pickle
2024-09-09 12:25:09.173 DEBUG (MainThread) [alexapy.alexalogin] Trying to load cookie from file /config/.storage/alexa_media.XXXXXXXXXXXX.pickle
2024-09-09 12:25:09.203 DEBUG (MainThread) [alexapy.alexalogin] Trying to load aiohttpCookieJar to session
2024-09-09 12:25:09.209 DEBUG (MainThread) [alexapy.alexalogin] Searching for cookies from /config/alexa_media.XXXXXXXXXXXX.pickle
2024-09-09 12:25:09.210 DEBUG (MainThread) [alexapy.alexalogin] Searching for cookies from /config/.storage/alexa_media.XXXXXXXXXXXX.txt
2024-09-09 12:25:09.210 DEBUG (MainThread) [alexapy.alexalogin] Using credentials to log in
2024-09-09 12:25:09.211 DEBUG (MainThread) [alexapy.alexalogin] Attempting oauth login to https://www.amazon.com/ap/signin?openid.return_to=https://www.amazon.com/ap/maplanding&openid.assoc_handle=amzn_dp_project_dee_ios&openid.identity=http://specs.openid.net/auth/2.0/identifier_select&pageId=amzn_dp_project_dee_ios&accountStatusPolicy=P1&openid.claimed_id=http://specs.openid.net/auth/2.0/identifier_select&openid.mode=checkid_setup&openid.ns.oa2=http://www.amazon.com/ap/ext/oauth/2&openid.oa2.client_id=device:653462623636623238616439623635656538626234353966333135646134363932333431333234393536346335363335353634643332353733383331&openid.ns.pape=http://specs.openid.net/extensions/pape/1.0&openid.oa2.response_type=code&openid.ns=http://specs.openid.net/auth/2.0&openid.pape.max_auth_age=0&openid.oa2.scope=device_auth_access&openid.oa2.code_challenge_method=S256&openid.oa2.code_challenge=XXXXXXXXXXXX&language=de_DE
2024-09-09 12:25:09.609 DEBUG (MainThread) [alexapy.alexalogin] GET: 
https://www.amazon.com/ap/signin?openid.return_to=https://www.amazon.com/ap/maplanding&openid.assoc_handle=amzn_dp_project_dee_ios&openid.identity=http://specs.openid.net/auth/2.0/identifier_select&pageId=amzn_dp_project_dee_ios&accountStatusPolicy=P1&openid.claimed_id=http://specs.openid.net/auth/2.0/identifier_select&openid.mode=checkid_setup&openid.ns.oa2=http://www.amazon.com/ap/ext/oauth/2&openid.oa2.client_id=device:653462623636623238616439623635656538626234353966333135646134363932333431333234393536346335363335353634643332353733383331&openid.ns.pape=http://specs.openid.net/extensions/pape/1.0&openid.oa2.response_type=code&openid.ns=http://specs.openid.net/auth/2.0&openid.pape.max_auth_age=0&openid.oa2.scope=device_auth_access&openid.oa2.code_challenge_method=S256&openid.oa2.code_challenge=XXXXXXXXXXXX&language=de_DE returned 200:OK with response <CIMultiDictProxy('Content-Type': 'text/html;charset=UTF-8', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Server': 'Server', 'Date': 'Mon, 09 Sep 2024 10:25:09 GMT', 'x-amz-rid': '04QM1D8MN5HVKGTSDFNN', 'Set-Cookie': 'ap-fid=""; Domain=.amazon.com; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/ap/; Secure', 'Set-Cookie': 'session-id=135-4217245-7778765; Domain=.amazon.com; Expires=Tue, 09-Sep-2025 10:25:09 GMT; Path=/; Secure', 'Set-Cookie': 'session-id-time=2356597509l; Domain=.amazon.com; Expires=Tue, 09-Sep-2025 10:25:09 GMT; Path=/; Secure', 'Set-Cookie': 'ubid-main=135-5053255-1128561; Domain=.amazon.com; Expires=Tue, 09-Sep-2025 10:25:09 GMT; Path=/; Secure', 'Set-Cookie': 'session-token=XXXXXXXXXXXX; Domain=.amazon.com; Expires=Tue, 09-Sep-2025 10:25:09 GMT; Path=/; Secure', 'X-XSS-Protection': '1', 'X-Content-Type-Options': 'nosniff', 'x-ua-compatible': 'IE=edge', 'Content-Security-Policy': "frame-ancestors 'none';", 'Pragma': 'No-cache', 'Cache-Control': 'max-age=0, no-cache, no-store, must-revalidate', 'Expires': 'Thu, 01 Jan 1970 00:00:00 GMT', 'Strict-Transport-Security': 'max-age=47474747; includeSubDomains; preload', 'Vary': 'Content-Type,Accept-Encoding,User-Agent', 'p3p': 'policyref="http://www.amazon.com/w3c/p3p.xml",CP="CAO DSP LAW CUR ADM IVAo IVDo CONo OTPo OUR DELi PUBi OTRi BUS PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA HEA PRE LOC GOV OTC "', 'X-Frame-Options': 'SAMEORIGIN', 'X-Cache': 'Miss from cloudfront', 'Via': '1.1 6b284415724869adc9db63c19e48e420.cloudfront.net (CloudFront)', 'X-Amz-Cf-Pop': 'FRA60-P9', 'Alt-Svc': 'h3=":443"; ma=86400', 'X-Amz-Cf-Id': 'WZmbNiolUTU_0MroMmZraGglYeN09LPgflxohl1aZ3_XefY2w-HwKw==')>
2024-09-09 12:25:09.866 DEBUG (MainThread) [alexapy.alexalogin] Processing https://www.amazon.com/ap/signin?openid.return_to=https://www.amazon.com/ap/maplanding&openid.assoc_handle=amzn_dp_project_dee_ios&openid.identity=http://specs.openid.net/auth/2.0/identifier_select&pageId=amzn_dp_project_dee_ios&accountStatusPolicy=P1&openid.claimed_id=http://specs.openid.net/auth/2.0/identifier_select&openid.mode=checkid_setup&openid.ns.oa2=http://www.amazon.com/ap/ext/oauth/2&openid.oa2.client_id=device:653462623636623238616439623635656538626234353966333135646134363932333431333234393536346335363335353634643332353733383331&openid.ns.pape=http://specs.openid.net/extensions/pape/1.0&openid.oa2.response_type=code&openid.ns=http://specs.openid.net/auth/2.0&openid.pape.max_auth_age=0&openid.oa2.scope=device_auth_access&openid.oa2.code_challenge_method=S256&openid.oa2.code_challenge=XXXXXXXXXXXX&language=de_DE
2024-09-09 12:25:10.023 DEBUG (MainThread) [alexapy.alexalogin] Found standard login page
2024-09-09 12:25:10.024 DEBUG (MainThread) [alexapy.alexalogin] Found post url to https://www.amazon.com/ap/register
2024-09-09 12:25:10.024 DEBUG (MainThread) [alexapy.alexalogin] Preparing form submission to https://www.amazon.com/ap/register with input data: {}
2024-09-09 12:25:10.024 DEBUG (MainThread) [alexapy.alexalogin] No 2FA code supplied but will generate.
2024-09-09 12:25:10.025 DEBUG (MainThread) [alexapy.alexalogin] Generating OTP XXXXXXXXXXXX
2024-09-09 12:25:10.499 DEBUG (MainThread) [alexapy.alexalogin] POST: 
https://www.amazon.com/ap/register returned 200:OK with response <CIMultiDictProxy('Content-Type': 'text/html;charset=UTF-8', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Server': 'Server', 'Date': 'Mon, 09 Sep 2024 10:25:10 GMT', 'x-amz-rid': '5R6K5HQTKVW89AFA09VP', 'Set-Cookie': 'session-id=135-4217245-7778765; Domain=.amazon.com; Expires=Tue, 09-Sep-2025 10:25:10 GMT; Path=/; Secure', 'Set-Cookie': 'session-id-time=2356597510l; Domain=.amazon.com; Expires=Tue, 09-Sep-2025 10:25:10 GMT; Path=/; Secure', 'Set-Cookie': 'ubid-main=135-5053255-1128561; Domain=.amazon.com; Expires=Tue, 09-Sep-2025 10:25:10 GMT; Path=/; Secure', 'Set-Cookie': 'session-token=XXXXXXXXXXXX; Domain=.amazon.com; Expires=Tue, 09-Sep-2025 10:25:10 GMT; Path=/; Secure', 'X-XSS-Protection': '1', 'X-Content-Type-Options': 'nosniff', 'x-ua-compatible': 'IE=edge', 'Pragma': 'No-cache', 'Cache-Control': 'max-age=0, no-cache, no-store, must-revalidate', 'Expires': 'Thu, 01 Jan 1970 00:00:00 GMT', 'Content-Security-Policy': "frame-ancestors 'none';", 'Strict-Transport-Security': 'max-age=47474747; includeSubDomains; preload', 'Vary': 'Content-Type,Accept-Encoding,User-Agent', 'p3p': 'policyref="http://www.amazon.com/w3c/p3p.xml",CP="CAO DSP LAW CUR ADM IVAo IVDo CONo OTPo OUR DELi PUBi OTRi BUS PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA HEA PRE LOC GOV OTC "', 'X-Frame-Options': 'SAMEORIGIN', 'X-Cache': 'Miss from cloudfront', 'Via': '1.1 6b284415724869adc9db63c19e48e420.cloudfront.net (CloudFront)', 'X-Amz-Cf-Pop': 'FRA60-P9', 'Alt-Svc': 'h3=":443"; ma=86400', 'X-Amz-Cf-Id': 'BZqqmgn4JvOnJAWaJjhCMFQdD4Eqdtu4Wdo0WlxbCaxxMwToX8zaIw==')>
2024-09-09 12:25:10.572 DEBUG (MainThread) [alexapy.alexalogin] Processing https://www.amazon.com/ap/register
2024-09-09 12:25:10.641 WARNING (MainThread) [alexapy.helpers] alexalogin.login((<alexapy.alexalogin.AlexaLogin object at 0x7fc88f5b5a00>,), {'cookies': {}}): An error occurred accessing AlexaAPI: An exception of type TypeError occurred. Arguments:
('can only concatenate str (not "NoneType") to str',)
2024-09-09 12:25:10.641 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry XXXXXXXXXXXX - amazon.de for alexa_media
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 604, in async_setup
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/alexa_media/__init__.py", line 361, in async_setup_entry
    await login.login(cookies=await login.load_cookie())
  File "/usr/local/lib/python3.12/site-packages/alexapy/helpers.py", line 137, in wrapper
    return await func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/alexapy/alexalogin.py", line 703, in login
    self._site = await self._process_page(await post_resp.text(), site)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/alexapy/alexalogin.py", line 1463, in _process_page
    error_message += list_item.find("span").string
TypeError: can only concatenate str (not "NoneType") to str
2024-09-09 12:25:38.006 DEBUG (MainThread) [custom_components.alexa_media] Completing remaining startup tasks.

Additional context

@cyberdie
Copy link

cyberdie commented Sep 9, 2024

Same with 2024.8.3

@r1si
Copy link

r1si commented Sep 9, 2024

Same here! 2024.9.1

@danielbrunt57
Copy link
Collaborator

danielbrunt57 commented Sep 10, 2024

It looks like your Amazon accounts do not have 2SV enabled using Authenticator App...

@martinhoess
Copy link

It looks like your Amazon accounts do not have 2SV enabled using Authenticator App...

2SV has been active for months, and nothing has changed there 🤷‍♂️
image
image

@cyberdie
Copy link

It looks like your Amazon accounts do not have 2SV enabled using Authenticator App...

Active for months too. It worked till now.

@danielbrunt57
Copy link
Collaborator

danielbrunt57 commented Sep 10, 2024

I've no idea why this is in your logs then...

2024-09-09 12:25:10.023 DEBUG (MainThread) [alexapy.alexalogin] Found standard login page
2024-09-09 12:25:10.024 DEBUG (MainThread) [alexapy.alexalogin] Found post url to https://www.amazon.com/ap/register
2024-09-09 12:25:10.024 DEBUG (MainThread) [alexapy.alexalogin] Preparing form submission to https://www.amazon.com/ap/register with input data: {}

My start up log for alexapy:

2024-09-10 00:25:26.191 DEBUG (ImportExecutor_0) [alexapy.alexalogin] sys.version_info: (3, 12)
alexapy Version: 1.29.1
2024-09-10 00:25:36.685 DEBUG (MainThread) [alexapy.alexalogin] Creating TOTP for K************************************************GJQ
2024-09-10 00:25:36.685 DEBUG (MainThread) [alexapy.alexalogin] Generating OTP 315319
2024-09-10 00:25:36.686 DEBUG (MainThread) [alexapy.alexalogin] Login created for d****@****a - amazon.ca
2024-09-10 00:25:36.687 DEBUG (MainThread) [alexapy.alexalogin] Searching for cookies from /config/.storage/alexa_media.daniel@brunt.ca.pickle
2024-09-10 00:25:36.687 DEBUG (MainThread) [alexapy.alexalogin] Trying to load cookie from file /config/.storage/alexa_media.daniel@brunt.ca.pickle
2024-09-10 00:25:36.791 DEBUG (MainThread) [alexapy.alexalogin] Trying to load aiohttpCookieJar to session
2024-09-10 00:25:36.807 DEBUG (MainThread) [alexapy.alexalogin] Loaded 15 cookies
2024-09-10 00:25:36.807 DEBUG (MainThread) [alexapy.alexalogin] Searching for cookies from /config/alexa_media.daniel@brunt.ca.pickle
2024-09-10 00:25:36.807 DEBUG (MainThread) [alexapy.alexalogin] Using cookies to log in
2024-09-10 00:25:36.808 DEBUG (MainThread) [alexapy.alexalogin] Attempting to register with amazon.ca
2024-09-10 00:25:38.045 DEBUG (MainThread) [alexapy.alexalogin] auth response <ClientResponse(https://api.amazon.ca/auth/register) [200 OK]>
2024-09-10 00:25:38.046 DEBUG (MainThread) [alexapy.alexalogin] Successfully registered Daniel's 2nd Alexa Media Player device with Amazon
2024-09-10 00:25:38.046 DEBUG (MainThread) [alexapy.alexalogin] New access token(375) received which expires at 2024-09-10 01:25:38.046495 in 0:59:59.999971
2024-09-10 00:25:38.341 DEBUG (MainThread) [alexapy.alexalogin] capabilities response <ClientResponse(https://api.amazonalexa.com/v1/devices/@self/capabilities) [204 No Content]>
2024-09-10 00:25:38.573 DEBUG (MainThread) [alexapy.alexalogin] updating jar with cookie Set-Cookie: session-id=131-2424994-9272064; Domain=.amazon.ca; expires=5 Sep 2044 07:25:38 GMT; Path=/; Secure
2024-09-10 00:25:38.574 DEBUG (MainThread) [alexapy.alexalogin] updating jar with cookie Set-Cookie: ubid-acbca=131-6169391-4913816; Domain=.amazon.ca; expires=5 Sep 2044 07:25:38 GMT; Path=/; Secure
2024-09-10 00:25:38.574 DEBUG (MainThread) [alexapy.alexalogin] updating jar with cookie Set-Cookie: x-acbca=uiXlA2xR2ocl9DcRygTvw4Akbgo8OEIp; Domain=.amazon.ca; expires=5 Sep 2044 07:25:38 GMT; Path=/; Secure
2024-09-10 00:25:38.574 DEBUG (MainThread) [alexapy.alexalogin] updating jar with cookie Set-Cookie: at-acbca=Atza|IwEBICLIRotOsLyEJgvKW4_ToukX1BBhEQPqJx4FmpTrQTQkK8gSq1mlnxTEMC5XaGWbwKzL9ECkaTq86ZMBmTnxbYiGl1o5gqa9BziLZggEFfPD8Yy-qvM-E62z73w9LRcgi795C0qG3bPkEveYZ3AQN4f2F53PFSoVuqKMosqnyg9xKMw9ySaduwRBcxyfv436aMkw7qdDrIXd4zdtVnUMPc7KiBtEWz2UxAUaG7kd-WAzT8fe-1MOeoc_HFj2NMhG82V72vDEQKEXMaEv6N2qS4cbQG6A9y4K2fvWyK-TYM0-LSK97ufqNZMCLFhA4xM-Ds5oXXfIV3YyCCzxNOO0qqo-PGiGqbjdnYEvZ6-52A6DUAk9cNaBi5Z8rUelHzN_db-V-xWpaGy_opjU8ZfPrGLc; Domain=.amazon.ca; expires=11 Sep 2024 07:25:38 GMT; HttpOnly; Path=/; Secure
2024-09-10 00:25:38.575 DEBUG (MainThread) [alexapy.alexalogin] updating jar with cookie Set-Cookie: sess-at-acbca="jyaFkHQEi/75Nw6UM1ZEIMIs87GsUvVrSp5CP8DFtvI="; Domain=.amazon.ca; expires=11 Sep 2024 07:25:38 GMT; HttpOnly; Path=/; Secure
2024-09-10 00:25:38.575 INFO (MainThread) [alexapy.alexalogin] Exchanged refresh token for 5 .amazon.ca cookies: ['session-id', 'ubid-acbca', 'x-acbca', 'at-acbca', 'sess-at-acbca']
2024-09-10 00:25:38.575 DEBUG (MainThread) [alexapy.alexalogin] CSRF already exists; no need to discover
2024-09-10 00:25:38.576 DEBUG (MainThread) [alexapy.alexalogin] Session cookies for 'https://alexa.amazon.com/api/bootstrap': ['session-id', 'session-id-time', 'lc-main', 'ubid-main', 'session-token', 'x-main', 'at-main', 'sess-at-main', 'csrf']
2024-09-10 00:25:38.882 DEBUG (MainThread) [alexapy.alexalogin] GET:
2024-09-10 00:25:38.883 DEBUG (MainThread) [alexapy.alexalogin] Session cookies for 'https://alexa.amazon.ca/api/bootstrap': ['session-id', 'session-id-time', 'lc-main', 'ubid-main', 'session-token', 'x-main', 'at-main', 'sess-at-main', 'ubid-acbca', 'x-acbca', 'at-acbca', 'sess-at-acbca', 'csrf', 'i18n-prefs', 'lc-acbca']
2024-09-10 00:25:39.171 DEBUG (MainThread) [alexapy.alexalogin] GET:
2024-09-10 00:25:39.171 DEBUG (MainThread) [alexapy.alexalogin] Logged in as d****@****a to amazon.ca with id: A1UZ93DGNU3F5L
2024-09-10 00:25:39.453 DEBUG (MainThread) [alexapy.alexalogin] Domain amazon.ca matches reported account domain: amazon.ca
2024-09-10 00:25:39.468 DEBUG (MainThread) [alexapy.alexalogin] Login confirmed for d****@****a - amazon.ca; saving cookie to /config/.storage/alexa_media.daniel@brunt.ca.pickle
2024-09-10 00:25:39.543 DEBUG (MainThread) [custom_components.alexa_media] d****l@b******a: HTTP2 created: <alexapy.alexahttp2.HTTP2EchoClient object at 0xffff77b70770>
2024-09-10 00:25:40.248 DEBUG (MainThread) [alexapy.alexahttp2] Starting message parsing loop.
2024-09-10 00:25:40.248 DEBUG (MainThread) [alexapy.alexahttp2] Connecting to https://alexa.na.gateway.devices.a2z.com/v20160207/directives with {'method': 'GET', 'path': '/v20160207/directives', 'authority': 'alexa.na.gateway.devices.a2z.com', 'scheme': 'https', 'authorization': 'Bearer Atna|EwICIBnvrbalcAcTYV2-3aA5fumxLFtfIBEGGrZLSLb_c50T8korJ_y1VxAxIaBxkiZva6Re9j3Zh9dAJBNdpDgzeog9iyMfdgylgApvJivqyGgNsTtO47l5Xw5YvMnix56BMw0BCGrS_6oRtZskBUmF0hfxMOpwiAmWrjjbe7_DMgiHLSZoylScuL47xwUhxga5ughoyKOLIfGABl4hH2doJUHM5QmH0C6yGn030Ccu2c1xZF_XiWhGt61RfOG3cH_JHUJhG77wZ4ZvOoBi7LHPHCpCZc9pkLtq02Hex7Xo9EVfs_A6HLYICIesr63l8tTxog7RMpkksYdsJbA8fjxVH1sd70LQxYV1HT_yslxdGH-WkA'}
2024-09-10 00:25:40.250 DEBUG (MainThread) [alexapy.alexahttp2] Preparing ping to https://alexa.na.gateway.devices.a2z.com/ping

@martinhoess
Copy link

So, I deleted everything again and re-added it. Now everything is working again.
I was at the same point two days ago. And after the 10th restart or so, it will probably break again. 🤷‍♂️

image

@martinhoess
Copy link

And it's broken again... I had already seen this error message a few days ago, but I couldn't find the log anymore.

It may work 1-2 times after a restart, and then the "concatenate str (not 'NoneType')" error comes back eventually.

2024-09-10 10:20:20.467 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry XXXXXXXXX - amazon.de for alexa_media
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 604, in async_setup
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/alexa_media/__init__.py", line 361, in async_setup_entry
    await login.login(cookies=await login.load_cookie())
                              ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/alexapy/alexalogin.py", line 328, in load_cookie
    cookies = pickle.loads(await myfile.read())
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/http/cookies.py", line 312, in __setitem__
    raise CookieError("Invalid attribute %r" % (K,))
http.cookies.CookieError: Invalid attribute 'partitioned'

@danielbrunt57
Copy link
Collaborator

http.cookies.CookieError: Invalid attribute 'partitioned'

That is the 3 month old "partitioned cookie problem".

I'm working on a possible new solution for that but another solution is to replace /usr/local/lib/python3.12/http/cookies.py with the version proposed in a Python 3.13 PR:
Ref: Support for Partitioned cookies attribute #112713
and gh-112713 : Add support for 'partitioned' attribute in http.cookies
Download the file here.

@utech-git
Copy link

utech-git commented Sep 11, 2024

Hello, everybody.

I dont' know if it helps the discussion (I didnt read it), but I ended up in this page while browsing for the error:

alexalogin.login((<alexapy.alexalogin.AlexaLogin object at 0x7fc88f5b5a00>,), {'cookies': {}}): An error occurred accessing AlexaAPI: An exception of type TypeError occurred. Arguments:
('can only concatenate str (not "NoneType") to str',)

My alexa media player integration was not working because of this error. I fixed up just by updating everything on my raspberry pi.

sudo apt-get update
suddo apt-get upgrade -y

And them everything was back to normal.

Hope it helps

@danielbrunt57
Copy link
Collaborator

My alexa media player integration was not working because of this error. I fixed up just by updating everything on my raspberry pi.

sudo apt-get update
suddo apt-get upgrade -y

And them everything was back to normal.

Hope it helps

I think it might as my suspicions are that caching of some sort, somewhere might be responsible...

@f18m
Copy link

f18m commented Sep 11, 2024

If it helps, I get the same type of error in my logs.
My Alexa Media is asking to re-authenticate and when I try to do so, I get to visit the Amazon website login screen. I click "Continue" on the screen pre-populated with my email address and I get back to that (I think there was a second page but I forgot). In the logs I see:

2024-09-11 08:34:41.292 WARNING (MainThread) [alexapy.helpers] alexaapi.get_state((<alexapy.alexaapi.AlexaAPI object at 0x7f0b1e7837a0>,), {}): An error occurred accessing AlexaAPI: An exception of type AlexapyLoginError occurred. Arguments:
2024-09-11 08:34:41.296 WARNING (MainThread) [alexapy.helpers] alexaapi.get_state((<alexapy.alexaapi.AlexaAPI object at 0x7f0b1e7b28d0>,), {}): An error occurred accessing AlexaAPI: An exception of type AlexapyLoginError occurred. Arguments:
2024-09-11 08:34:42.805 WARNING (MainThread) [alexapy.helpers] alexaapi.run_behavior((<alexapy.alexaapi.AlexaAPI object at 0x7f0b1e7b28d0>, {'@type': 'com.amazon.alexa.behaviors.model.OpaquePayloadOperationNode', 'type': 'Alexa.DeviceControls.Volume', 'operationPayload': {'deviceType': 'A2DS1Q2TPDJ48U', 'deviceSerialNumber': 'G************0CK', 'locale': 'it-it', 'customerId': 'A**********M8E', 'value': 54.0}}), {'queue_delay': 1.5}): An error occurred accessing AlexaAPI: An exception of type AlexapyLoginError occurred. Arguments:
2024-09-11 08:34:42.805 WARNING (MainThread) [alexapy.helpers] alexaapi.send_sequence((<alexapy.alexaapi.AlexaAPI object at 0x7f0b1e7b28d0>, 'Alexa.DeviceControls.Volume'), {'customer_id': 'A3I6JFYIK91M8E', 'value': 54.0, 'queue_delay': 1.5}): An error occurred accessing AlexaAPI: An exception of type AlexapyLoginError occurred. Arguments:
2024-09-11 08:34:42.805 WARNING (MainThread) [alexapy.helpers] alexaapi.set_volume((<alexapy.alexaapi.AlexaAPI object at 0x7f0b1e7b28d0>, 0.54), {}): An error occurred accessing AlexaAPI: An exception of type AlexapyLoginError occurred. Arguments:
  File "/usr/local/lib/python3.12/site-packages/alexapy/helpers.py", line 137, in wrapper
  File "/usr/local/lib/python3.12/site-packages/alexapy/alexaapi.py", line 1111, in set_volume
  File "/usr/local/lib/python3.12/site-packages/alexapy/helpers.py", line 137, in wrapper
  File "/usr/local/lib/python3.12/site-packages/alexapy/alexaapi.py", line 512, in send_sequence
  File "/usr/local/lib/python3.12/site-packages/alexapy/helpers.py", line 137, in wrapper
  File "/usr/local/lib/python3.12/site-packages/alexapy/alexaapi.py", line 434, in run_behavior
  File "/usr/local/lib/python3.12/site-packages/alexapy/alexaapi.py", line 226, in _post_request
  File "/usr/local/lib/python3.12/site-packages/alexapy/alexaapi.py", line 199, in _request
alexapy.errors.AlexapyLoginError: Login error detected; not contacting API
2024-09-11 08:45:08.860 WARNING (MainThread) [alexapy.helpers] alexaapi.get_customer_history_records((<alexapy.alexalogin.AlexaLogin object at 0x7f0b35a1cd40>,), {'max_record_size': 10}): An error occurred accessing AlexaAPI: An exception of type AlexapyLoginError occurred. Arguments:
2024-09-11 08:45:08.860 WARNING (MainThread) [alexapy.helpers] alexaapi.get_last_device_serial((<alexapy.alexalogin.AlexaLogin object at 0x7f0b35a1cd40>,), {}): An error occurred accessing AlexaAPI: An exception of type AlexapyLoginError occurred. Arguments:
2024-09-11 10:00:48.712 WARNING (MainThread) [alexapy.helpers] alexaapi.get_state((<alexapy.alexaapi.AlexaAPI object at 0x7f0b1e7837a0>,), {}): An error occurred accessing AlexaAPI: An exception of type AlexapyLoginError occurred. Arguments:
2024-09-11 10:00:48.716 WARNING (MainThread) [alexapy.helpers] alexaapi.get_state((<alexapy.alexaapi.AlexaAPI object at 0x7f0b1e7b28d0>,), {}): An error occurred accessing AlexaAPI: An exception of type AlexapyLoginError occurred. Arguments:
2024-09-11 10:00:50.226 WARNING (MainThread) [alexapy.helpers] alexaapi.run_behavior((<alexapy.alexaapi.AlexaAPI object at 0x7f0b1e7b28d0>, {'@type': 'com.amazon.alexa.behaviors.model.OpaquePayloadOperationNode', 'type': 'Alexa.DeviceControls.Volume', 'operationPayload': {'deviceType': 'A2DS1Q2TPDJ48U', 'deviceSerialNumber': 'G************0CK', 'locale': 'it-it', 'customerId': 'A**********M8E', 'value': 54.0}}), {'queue_delay': 1.5}): An error occurred accessing AlexaAPI: An exception of type AlexapyLoginError occurred. Arguments:
2024-09-11 10:00:50.226 WARNING (MainThread) [alexapy.helpers] alexaapi.send_sequence((<alexapy.alexaapi.AlexaAPI object at 0x7f0b1e7b28d0>, 'Alexa.DeviceControls.Volume'), {'customer_id': 'A3I6JFYIK91M8E', 'value': 54.0, 'queue_delay': 1.5}): An error occurred accessing AlexaAPI: An exception of type AlexapyLoginError occurred. Arguments:
2024-09-11 10:00:50.226 WARNING (MainThread) [alexapy.helpers] alexaapi.set_volume((<alexapy.alexaapi.AlexaAPI object at 0x7f0b1e7b28d0>, 0.54), {}): An error occurred accessing AlexaAPI: An exception of type AlexapyLoginError occurred. Arguments:
  File "/usr/local/lib/python3.12/site-packages/alexapy/helpers.py", line 137, in wrapper
  File "/usr/local/lib/python3.12/site-packages/alexapy/alexaapi.py", line 1111, in set_volume
  File "/usr/local/lib/python3.12/site-packages/alexapy/helpers.py", line 137, in wrapper
  File "/usr/local/lib/python3.12/site-packages/alexapy/alexaapi.py", line 512, in send_sequence
  File "/usr/local/lib/python3.12/site-packages/alexapy/helpers.py", line 137, in wrapper
  File "/usr/local/lib/python3.12/site-packages/alexapy/alexaapi.py", line 434, in run_behavior
  File "/usr/local/lib/python3.12/site-packages/alexapy/alexaapi.py", line 226, in _post_request
  File "/usr/local/lib/python3.12/site-packages/alexapy/alexaapi.py", line 199, in _request
alexapy.errors.AlexapyLoginError: Login error detected; not contacting API
2024-09-11 10:00:52.718 WARNING (MainThread) [alexapy.helpers] alexaapi.get_state((<alexapy.alexaapi.AlexaAPI object at 0x7f0b1e7837a0>,), {}): An error occurred accessing AlexaAPI: An exception of type AlexapyLoginError occurred. Arguments:
2024-09-11 10:00:52.720 WARNING (MainThread) [alexapy.helpers] alexaapi.get_state((<alexapy.alexaapi.AlexaAPI object at 0x7f0b1e7b28d0>,), {}): An error occurred accessing AlexaAPI: An exception of type AlexapyLoginError occurred. Arguments:
2024-09-11 10:00:54.228 WARNING (MainThread) [alexapy.helpers] alexaapi.run_behavior((<alexapy.alexaapi.AlexaAPI object at 0x7f0b1e7b28d0>, {'@type': 'com.amazon.alexa.behaviors.model.OpaquePayloadOperationNode', 'type': 'Alexa.DeviceControls.Volume', 'operationPayload': {'deviceType': 'A2DS1Q2TPDJ48U', 'deviceSerialNumber': 'G************0CK', 'locale': 'it-it', 'customerId': 'A**********M8E', 'value': 54.0}}), {'queue_delay': 1.5}): An error occurred accessing AlexaAPI: An exception of type AlexapyLoginError occurred. Arguments:
2024-09-11 10:00:54.228 WARNING (MainThread) [alexapy.helpers] alexaapi.send_sequence((<alexapy.alexaapi.AlexaAPI object at 0x7f0b1e7b28d0>, 'Alexa.DeviceControls.Volume'), {'customer_id': 'A3I6JFYIK91M8E', 'value': 54.0, 'queue_delay': 1.5}): An error occurred accessing AlexaAPI: An exception of type AlexapyLoginError occurred. Arguments:
2024-09-11 10:00:54.228 WARNING (MainThread) [alexapy.helpers] alexaapi.set_volume((<alexapy.alexaapi.AlexaAPI object at 0x7f0b1e7b28d0>, 0.54), {}): An error occurred accessing AlexaAPI: An exception of type AlexapyLoginError occurred. Arguments:
  File "/usr/local/lib/python3.12/site-packages/alexapy/helpers.py", line 137, in wrapper
  File "/usr/local/lib/python3.12/site-packages/alexapy/alexaapi.py", line 1111, in set_volume
  File "/usr/local/lib/python3.12/site-packages/alexapy/helpers.py", line 137, in wrapper
  File "/usr/local/lib/python3.12/site-packages/alexapy/alexaapi.py", line 512, in send_sequence
  File "/usr/local/lib/python3.12/site-packages/alexapy/helpers.py", line 137, in wrapper
  File "/usr/local/lib/python3.12/site-packages/alexapy/alexaapi.py", line 434, in run_behavior
  File "/usr/local/lib/python3.12/site-packages/alexapy/alexaapi.py", line 226, in _post_request
  File "/usr/local/lib/python3.12/site-packages/alexapy/alexaapi.py", line 199, in _request
alexapy.errors.AlexapyLoginError: Login error detected; not contacting API
2024-09-11 10:01:05.023 WARNING (MainThread) [alexapy.helpers] alexalogin.login((<alexapy.alexalogin.AlexaLogin object at 0x7f0b35a1cd40>,), {'data': OrderedDict({'otp_secret': 'U************************************************7OQ', 'email': 'f**m@h*********m', 'password': 'REDACTED 10 CHARS', 'url': 'amazon.it', 'scan_interval': 60, 'include_devices': '', 'exclude_devices': '', 'debug': False, 'reauth': True})}): An error occurred accessing AlexaAPI: An exception of type TypeError occurred. Arguments:
2024-09-11 10:01:05.023 WARNING (MainThread) [custom_components.alexa_media.config_flow] Unknown error: can only concatenate str (not "NoneType") to str


@JonReed
Copy link

JonReed commented Sep 12, 2024

cant add any extra information, except to say having the same error:

alexalogin.login((<alexapy.alexalogin.AlexaLogin object at 0x7f2f5eb236b0>,), {'cookies': {}}): An error occurred accessing AlexaAPI: An exception of type TypeError occurred. Arguments: ('can only concatenate str (not "NoneType") to str',)

@danielbrunt57
Copy link
Collaborator

@f18m

My Alexa Media is asking to re-authenticate and when I try to do so, I get to visit the Amazon website login screen. I click "Continue" on the screen pre-populated with my email address and I get back to that (I think there was a second page but I forgot). In the logs I see:

When you visit the Amazon login page with email address, instead of clicking "continue" on the email screen, try selecting the option to create a new account (bear with me). Enter anything at all for First name & Last name (like "Q W") and submit. Amazon will then inform you that it already has an account for that email. Switch back to login with email & password, which should now be on one screen, click continue and you should then see the OTP screen. I spent several hours trying to figure out what's going on and decided to try Create New Account just to see what would happen and thereby discovered the above.
I don't know yet why it's doing this now but I suspect either Amazon segregated the initial email & password screens or something has changed yet again in HA Core 2024.9.1 as I just started seeing this behaviour.

@jleinenbach
Copy link
Contributor

I believe I remember encountering this error when I was also stuck in Amazon's login loop, where no cookie could be saved. The error likely isn't being caught properly but seems to occur only when there's an issue on Amazon's side. Unfortunately, I regret that the logs for this issue have already been deleted.

@danielbrunt57
Copy link
Collaborator

danielbrunt57 commented Sep 13, 2024

This is the log entry I saw when I was stuck in the login loop (it was still in an open notepad on my PC).
It's way beyond my skill level to understand what it's doing:

2024-09-11 19:55:20.096 DEBUG (MainThread) [alexapy.alexalogin] Attempting oauth login to 
https://www.amazon.com/ap/signin?openid.return_to=https://www.amazon.com/ap/maplanding
&openid.assoc_handle=amzn_dp_project_dee_ios
&openid.identity=http://specs.openid.net/auth/2.0/identifier_select
&pageId=amzn_dp_project_dee_ios&accountStatusPolicy=P1
&openid.claimed_id=http://specs.openid.net/auth/2.0/identifier_select
&openid.mode=checkid_setup
&openid.ns.oa2=http://www.amazon.com/ap/ext/oauth/2
&openid.oa2.client_id=device:306332613434373737663435316666316161363763666236643834666439623032333431333234393536346335363335353634643332353733383331
&openid.ns.pape=http://specs.openid.net/extensions/pape/1.0
&openid.oa2.response_type=code
&openid.ns=http://specs.openid.net/auth/2.0
&openid.pape.max_auth_age=0
&openid.oa2.scope=device_auth_access
&openid.oa2.code_challenge_method=S256
&openid.oa2.code_challenge=qVNqbCRsP24g1duhlpooF7diPzrkzDrkUzE49chzygI
&language=en_CA

https://www.amazon.com/ap/maplanding
?openid.assoc_handle=amzn_dp_project_dee_ios&openid.claimed_id=https%3A%2F%2Fwww.amazon.com%2Fap%2Fid%2Famzn1.account.AE2UYTSC4T77TJMTK7HVKA4SHSJQ
&openid.identity=https%3A%2F%2Fwww.amazon.com%2Fap%2Fid%2Famzn1.account.AE2UYTSC4T77TJMTK7HVKA4SHSJQ
&openid.mode=id_res
&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0
&openid.op_endpoint=https%3A%2F%2Fwww.amazon.com%2Fap%2Fsignin
&openid.response_nonce=2024-09-12T03%3A23%3A09Z4782521131671538174
&openid.return_to=https%3A%2F%2Fwww.amazon.com%2Fap%2Fmaplanding
&openid.signed=assoc_handle%2Cclaimed_id%2Cidentity%2Cmode%2Cns%2Cop_endpoint%2Cresponse_nonce%2Creturn_to%2Cns.pape%2Cpape.auth_policies%2Cpape.auth_time%2Coa2.authorization_code%2Csigned
&openid.ns.pape=http%3A%2F%2Fspecs.openid.net%2Fextensions%2Fpape%2F1.0
&openid.pape.auth_policies=http%3A%2F%2Fschemas.openid.net%2Fpape%2Fpolicies%2F2007%2F06%2Fmulti-factor
&openid.pape.auth_time=2024-09-12T03%3A23%3A03Z
&openid.sig=AAu6mU%2FQyKHqCZe%2FxOwB3%2B4TALALHqJwxBRCk3seAZ8%3D
&serial=
&openid.oa2.authorization_code=ANtkoxeNBHOlUOCwIOTQIKof
&openid.ns.oa2=http%3A%2F%2Fwww.amazon.com%2Fap%2Fext%2Foauth%2F2

@danielbrunt57
Copy link
Collaborator

I was also seeing the initial captcha window which is something I have not encountered for a very long time.

@danielbrunt57
Copy link
Collaborator

Issue #2514 is related to this

@deifel
Copy link

deifel commented Sep 13, 2024

Hello everyone, I've also had the error (TypeError: can only concatenate str (not "NoneType") to str) for 3 days or one of the last updates.
Is there a solution now or is it being worked on? Currently, some automations are no longer working because of this.
Thank you very much

@cyberdie
Copy link

cyberdie commented Sep 13, 2024 via email

@jleinenbach
Copy link
Contributor

ChatGPT:

The error you're encountering is a TypeError caused by trying to concatenate a string with a NoneType object during the login process for the alexa_media integration in Home Assistant. The error occurs in this code snippet:

error_message += list_item.find("span").string

Breakdown of the Issue:

  1. Cause:
    The program is trying to append text from an HTML span element, but list_item.find("span").string is returning None. This happens when the expected span element is either missing or empty, potentially due to an unexpected or malformed response from Amazon's login page.

  2. Potential Causes:

    • Amazon Service Disruption: Amazon recently had an issue with its Identity and Access Management (IAM) service, which affected authentication processes globally. This could have led to incomplete or incorrect HTML being returned, resulting in the login loop and the error you're seeing.
    • OAuth Login Attempt: The login process involves an OAuth flow, where the system uses a time-based one-time password (TOTP) and cookies to authenticate the session. In this case, the issue likely arises when the response page doesn't load properly, interrupting the OAuth process and redirecting incorrectly to a registration page, as seen in your earlier logs.
  3. Solution:

    • Modify the Python Code: The program needs to handle cases where no text is found in the span element:

      span_text = list_item.find("span").string
      if span_text:  # Only append if span_text is not None
          error_message += span_text

      This simple check ensures the program won't break if the element is empty, preventing the TypeError.

    • Clear Cookies: Old or corrupted cookies could cause faulty authentication attempts. You can delete the saved cookie files and restart the login process, allowing fresh cookies to be generated:

      rm /config/.storage/alexa_media.*.pickle
    • Wait for Stabilization: Given Amazon's recent IAM issues, retrying after services fully stabilize may resolve the problem without requiring further changes.

OAuth Context:

During the login process, the system initiates an OAuth login attempt, where it exchanges credentials for access tokens via an external service (Amazon). If the response during this attempt is malformed or incomplete, the login process could fail, leading to the errors you are seeing. Properly handling these scenarios by checking for missing elements or corrupted session data can help prevent these issues.

By following these steps, you should be able to resolve the error and avoid the login loop caused by this unexpected behavior.

@jleinenbach
Copy link
Contributor

@cyberdie

I had the same error, reinstalled the integration from HACS (after deleting the pickle file in the .storage folder of HA) and now is working ok for 3 days.

Anyone experiencing this issue should try clearing potentially corrupted cookies, as this could help resolve the problem.

@deifel
Copy link

deifel commented Sep 13, 2024

I deleted the pickl file and removed the addon. If i now try to reinstall and configure it, i also get a loop on login page on amazon.

@jleinenbach
Copy link
Contributor

I deleted the pickl file and removed the addon. If i now try to reinstall and configure it, i also get a loop on login page on amazon.

Reboot again, then try Daniel's sequence

@deifel
Copy link

deifel commented Sep 13, 2024

Works für 3 hours - now the error (NoneType...) is back :(

@jleinenbach
Copy link
Contributor

jleinenbach commented Sep 13, 2024

Works für 3 hours - now the error (NoneType...) is back :(

init.py.txt

You may try my __init__.py file version:

  1. Rename __init__.py.txt to __init__.py.
  2. Make a backup of your original config\custom_components\alexa_media\__init__.py file. (e.g. rename it)
  3. Move __init__.py in your config\custom_components\alexa_media\ directory.
  4. reboot
  5. Retry with Daniel's sequence

My version tries to give you more useful error messages and retries to log in.
If it fails, please post your logs. Maybe we can see more, maybe not. (Depends on where it fails.)

@honkerst
Copy link

honkerst commented Sep 13, 2024

I just updated HA from 2024.7.3 to 2024.9.1 and immediately encountered this error. Alexa has previously been working fine for months. Reloading integration and rebooting HA had no effect, nor did deleting my pickle and rebooting. I eventually restored from backup to 2024.7.3 and Alexa is working again. (This makes me wonder how this can be an Amazon problem, it must be something on our end). Following this for a fix.

@fuzzysb
Copy link

fuzzysb commented Sep 13, 2024

there is a new alexapy version that fixes cookie issues, i just changed the version in the manifest to "alexapy==1.29.2" and then restarted, then reset back up and ensured i added the code for 2fa and all seems to be back up and running

@danielbrunt57
Copy link
Collaborator

there is a new alexapy version that fixes cookie issues, i just changed the version in the manifest to "alexapy==1.29.2" and then restarted, then reset back up and ensured i added the code for 2fa and all seems to be back up and running

When you set it back up, did you encounter a captcha window and then the endless loop from email to password back to email pages?

@BombusAlpinus
Copy link

same error here, alexa media player worked (more or less) for the last weeks. since today it doesnt start and i got the same behavior as mentioned by @danielbrunt57. changed manifest to 1.29.2 like @fuzzysb did and tried to configure integration
and also got a mail - password - mail and so on loop.

@r1si
Copy link

r1si commented Sep 21, 2024

Today I updated to 4.13.2 with a broken instance. It fixed itself after restarting. I'm mildly optimistic.

How did you update?
I updated from HACS but it still remains “fail to setup”

in log error is same
can only concatenate str (not "NoneType") to str

@matteo-martinelli
Copy link

Today I updated to 4.13.2 with a broken instance. It fixed itself after restarting. I'm mildly optimistic.

How did you update?
I updated from HACS but it still remains “fail to setup”

in log error is same
can only concatenate str (not "NoneType") to str

Same for me!

@jumavi
Copy link

jumavi commented Sep 21, 2024

I'm still the same, I remove the devices, uninstall the integration, reinstall it, do the whole authentication process successfully, it detects the devices correctly, but after a while, I haven't been able to determine how much, it asks me to re-authenticate and I have to do the whole process again.

@danielbrunt57
Copy link
Collaborator

I also have a side problem. Right now the integration is not going. so notify.alexa_media does not exist. All my automations that use that service (action) now no longer work.

Has anyone found a way to put a try catch without removing the service altogether?

I tried with continue_on_error: true creating a proxy service but nothing always crashes for “action does not exist”

@r1si Elia,

I am using a python script which will issue a persistent notification if the notify.alexa_media action fails.
Install HA's Python Scripts
Create these files in the <config>/python_scripts/ folder:

# notify_alexa_media.py
domain = "notify"
service = data.get("service")
message = data.get("message")
flag = False

if service is not None and message is not None:
    service_data = {"message": message }
    try:
        hass.services.call(domain, service, service_data, flag)
    except:
        hass.services.call(
            "persistent_notification", "create", {
                "message": "Failed to call notify.{service}",
                "title": "Notify Alexa Media",
                "notification_id": "notify.alexa_media"
            }
        )
else:
    if service is None:
        hass.services.call(
            "persistent_notification", "create", {
                "message": "Missing required parameter \"service:\"",
                "title": "Notify Alexa Media",
                "notification_id": "notify.alexa_media"
            }
        )
    if message is None:
        hass.services.call(
            "persistent_notification", "create", {
                "message": "Missing required parameter \"message:\"",
                "title": "Notify Alexa Media",
                "notification_id": "notify.alexa_media"
            }
        )
# services.yaml
notify_alexa_media:
  name: notify.alexa_media
  description: Send a notification via Alexa Media Notification actions
  fields:
    service:
      description: The alexa_media notification service to append to "notify."
      example: "alexa_media_last_called"
    message:
      description: The message to be sent
      example: "Hello, this is a test"

In Developer tools > Actions, execute python_script.reload.
Test the script in Dev Tools: python_script.notify_alexa_media.
Once working, you can replace your notify.alexa_media_xyz actions with python_script.notify_alexa_media:

action: python_script.notify_alexa_media
data:
  service: alexa_media_last_called
  message: Hello, this is a test

@danielbrunt57
Copy link
Collaborator

I'm still the same, I remove the devices, uninstall the integration, reinstall it, do the whole authentication process successfully, it detects the devices correctly, but after a while, I haven't been able to determine how much, it asks me to re-authenticate and I have to do the whole process again.

First, make sure OTP/Amazon 2SV via App is set up correctly and that you have provided the OTP secret to AMP so that it can generate new OTP codes when it needs to reauthenticate with Amazon.
Then, start with a clean slate...
Delete the config entry.
Redownload the AMP custom component in HACS and restart HA.
Check if either of these files exist in <config>/.storage:

cd /config/.storage
ls -al alexa_*
-rw-r--r--    1 root     root           783 Sep 22 16:40 alexa_auth
-rw-r--r--    1 root     root          8480 Sep 22 16:54 alexa_media.<your_email>.pickle

If so, delete them, restart HA and verify they do not exist.
Clear your browser's cookies and then log into Amazon to reestablish its cookies.
Now re-add the integration.

@jumavi
Copy link

jumavi commented Sep 23, 2024

I'm still the same, I remove the devices, uninstall the integration, reinstall it, do the whole authentication process successfully, it detects the devices correctly, but after a while, I haven't been able to determine how much, it asks me to re-authenticate and I have to do the whole process again.

First, make sure OTP/Amazon 2SV via App is set up correctly and that you have provided the OTP secret to AMP so that it can generate new OTP codes when it needs to reauthenticate with Amazon. Then, start with a clean slate... Delete the config entry. Redownload the AMP custom component in HACS and restart HA. Check if either of these files exist in <config>/.storage:

cd /config/.storage
ls -al alexa_*
-rw-r--r--    1 root     root           783 Sep 22 16:40 alexa_auth
-rw-r--r--    1 root     root          8480 Sep 22 16:54 alexa_media.<your_email>.pickle

If so, delete them, restart HA and verify they do not exist. Clear your browser's cookies and then log into Amazon to reestablish its cookies. Now re-add the integration.

Captura de pantalla 2024-09-23 a las 20 22 51

I only have one file with .pickle extension, the other one is not in the folder (see capture). That is correct?

@danielbrunt57
Copy link
Collaborator

danielbrunt57 commented Sep 25, 2024

in log error is same
can only concatenate str (not "NoneType") to str

That is coming from an errorbox window which AMP is no longer able to process as Amazon has likely changed the formatting.
Editing /usr/local/lib/python3.12/site-packages/alexapy/alexalogin.py to this should allow it to process that errorbox without an error, but there really should not be an errorbox window if everything succeeded.

        # pull out Amazon error message

        if errorbox:
            error_message = errorbox.find("h4").string
            if error_message is None:
                error_message = "unknown"
            for list_item in errorbox.findAll("li"):
                span_text = list_item.find("span").string
                if span_text:
                    error_message += span_text
            _LOGGER.debug("Error message: %s", error_message)
            status["error_message"] = error_message

@danielbrunt57
Copy link
Collaborator

@jumavi I suggest your email + password & OTP secret is failing. After AMP ascertains credentials succeeded during the proxy authentication step, it uses those credentials to generate a token which has an expiry and has to renewed by providing credentials again. The current token is stored in alexa_auth.

/config/.storage $ ls -al alexa_*
-rw-r--r--    1 root     root           783 Sep 25 11:32 alexa_auth
-rw-r--r--    1 root     root          8480 Sep 25 11:29 alexa_media.d*****@*******a.pickle
/config/.storage  $ cat alexa_auth
{
  "version": 1,
  "minor_version": 1,
  "key": "alexa_auth",
  "data": {
    "access_token": "Atza|IwEBIHpFIOAdMKYbn1-Kc1zZnsJgHBu3DlS35zA5wKqJDSlcBa8BH8-x6JU2sxoXsSqPxQhR8M3Ey1tWXDmEvAUJqkiXB5Ct80ExIl4HonKq_l7Eea2_3fxmq8DogKgTiClmc_udBGHkuiLws10ewpVodly58S4vaaKITbtaUqmDSc19vubgXYCtUAlck-cM0tLPfIycsR0nqOu8w6sajGa5axLUG5lzxv7emcpT236GsxztkKWsqKcCyHqp_oaN3m82-6HkjWZiYhmRwNt6i2rah6FC3dOTzolclVfcc8fJ9Qa94A",
    "refresh_token": "Atzr|IwEBIO7SFesfNke3ow2m2Hd_STXAJ5X6eF4Ki2PEKD3C_U8e-iRdu1ycDABu4qczSKw3d6HUrtb0_SV2I2-kenYtj64iD1q-0PCKKqB0BWg4zg-S44hMhJ7FUSgm2Ld7c00GruWTwwzl6hUzI_5QX-f5RvQnGS7XxtJ6gwJT3Ip1QQEjMbjVyWFlicjrQjtfkc2wMc3xCxqHCo2EwUvQPUE7fDVivTUc7-1KBKnl2U_IKPIUb74b98Vcpi243KIrKF1Wkkh81LRDDZq5fpZTfC-g34XE",
    "expire_time": "2024-09-25T19:32:01.305519+00:00"
  }
}

@danielbrunt57
Copy link
Collaborator

danielbrunt57 commented Sep 25, 2024

I have encountered several of the errors reported (re-auth, cannot concatenate None type str error, etc.) but was always able to fix as follows...

First, make sure OTP/Amazon 2SV via App is set up correctly and that you have provided the OTP secret to AMP so that it can generate new OTP codes when it needs to reauthenticate with Amazon.
Then, start with a clean slate...
Delete the config entry.
Redownload the AMP custom component in HACS and restart HA.
Check if this file exist in /.storage:

cd /config/.storage
ls -al *pickle
-rw-r--r-- 1 root root 8480 Sep 22 16:54 alexa_media.<your_email>.pickle

If so, delete it, restart HA and verify it does not exist.
Clear your browser's cookies, restart the browser and then log into Amazon to reestablish its cookies. <- This was critical for me numerous times!
Now login into HA and try re-adding the integration.

@r1si
Copy link

r1si commented Sep 28, 2024

I deleted the files, followed the procedure but after 3 days it stopped working again.

Do you think it is possible in the future to have a fix directly in the HACS package?

@holocronweaver
Copy link

holocronweaver commented Sep 29, 2024

Upgraded from HA 2024.7.3 to 2024.9.3 and encountered this issue within a few hours. Using AMP 4.13.2 on both HA versions, so this may be a HA regression.

@jumavi
Copy link

jumavi commented Sep 29, 2024

I resign, I have tried everything or at least I think so and the final result is always the same then after a very short time, it asks me to re-authenticate again

@Capelare
Copy link

Capelare commented Sep 30, 2024

I have encountered several of the errors reported (re-auth, cannot concatenate None type str error, etc.) but was always able to fix as follows...

First, make sure OTP/Amazon 2SV via App is set up correctly and that you have provided the OTP secret to AMP so that it can generate new OTP codes when it needs to reauthenticate with Amazon. Then, start with a clean slate... Delete the config entry. Redownload the AMP custom component in HACS and restart HA. Check if either of these files exist in /.storage:

cd /config/.storage
ls -al alexa_*
-rw-r--r-- 1 root root 783 Sep 22 16:40 alexa_auth
-rw-r--r-- 1 root root 8480 Sep 22 16:54 alexa_media.<your_email>.pickle

If so, delete them, restart HA and verify they do not exist. Clear your browser's cookies, restart the browser and then log into Amazon to reestablish its cookies. <- This was critical for me numerous times! Now login into HA and try re-adding the integration.

I followed these steps but I also previously run apk upgrade on HAOS as suggested by another commenter and so far it's been working fine for a couple of days. I'll report back if it breaks again.

@dperauletTradesegur
Copy link

Hello, I have an installation of Home Assistan OS and after trying all the proposed solutions I always got the TypeError: can only... Yesterday I rolled back to the Core 2024.7.3 version and it seems to be maintained and working correctly

@r1si
Copy link

r1si commented Oct 8, 2024

Someone has test test the 4.13.4 version?

@holocronweaver
Copy link

holocronweaver commented Oct 8, 2024

@r1si None of the changes in 4.13.4 appear related to this issue.

@danielbrunt57
Copy link
Collaborator

danielbrunt57 commented Oct 8, 2024

There is some weird sequencing of events you all have which is triggering Amazon to issue a revised login error window which AMP can no longer deal with. When the stars are aligned, that errorbox window does not occur thus there's no error.

File "/usr/local/lib/python3.12/site-packages/alexapy/alexalogin.py", line 1463, in _process_page
error_message += list_item.find("span").string
TypeError: can only concatenate str (not "NoneType") to str

I've modified my alexalogin.py to only concatenate the error message if the errorbox window contains the html <span> element but it will take time before a new alexapy is released with the code change and for AMP to use a new alexapy:

        # pull out Amazon error message

        if errorbox:
            error_message = errorbox.find("h4").string
            for list_item in errorbox.findAll("li"):
                span_text = list_item.find("span").string
                if span_text:
                    error_message += span_text
            _LOGGER.debug("Error message: %s", error_message)
            status["error_message"] = error_message

@r1si
Copy link

r1si commented Oct 8, 2024

Thanks for this! What do you mean with need time ?

@danielbrunt57
Copy link
Collaborator

Thanks for this! What do you mean with need time ?

See alexapy merge request !391 which is already two weeks old now.

@kompre
Copy link

kompre commented Oct 21, 2024

I've updated to v4.13.5 and still the integration fails some time after doing a log-in.

I think now I am on this bandwagon #2453

Did anybody on this thread has been able to fully solve their issue with this update?

@f18m
Copy link

f18m commented Oct 21, 2024

I also updated to v4.13.5 and the integration failed some time after doing a log-in, also for me....

@danielbrunt57
Copy link
Collaborator

I give up...
¯_(ツ)_/¯

@cagnulein
Copy link

Thanks for this! What do you mean with need time ?

See alexapy merge request !391 which is already two weeks old now.

It's merged but I don't see it in the latest Hass changes log, am I wrong?

@martin3000
Copy link

It's merged but I don't see it in the latest Hass changes log, am I wrong?

alexapy is a python package that is used by HA, but does not belong to HA

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