alexa_media_player: TypeError: can only concatenate str (not "NoneType") to str
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 https://github.com/alandtse/alexa_media_player/issues/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
System details
- Home Assistant version: 2024.9.1
- alexa_media version (from
const.pyor HA startup log): 4.12.12 - alexapy version (from
pip show alexapyin 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
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 3
- Comments: 77 (5 by maintainers)
Commits related to this issue
- fix: bump alexapy to 1.29.3 (#2634) closes #2514 closes #2515 — committed to alandtse/alexa_media_player by srescio 2 years ago
ChatGPT:
The error you’re encountering is a TypeError caused by trying to concatenate a string with a
NoneTypeobject during the login process for thealexa_mediaintegration in Home Assistant. The error occurs in this code snippet:Breakdown of the Issue:
Cause:
The program is trying to append text from an HTML
spanelement, butlist_item.find("span").stringis returningNone. This happens when the expectedspanelement is either missing or empty, potentially due to an unexpected or malformed response from Amazon’s login page.Potential Causes:
Solution:
Modify the Python Code: The program needs to handle cases where no text is found in the
spanelement: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:
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.
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.
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
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
alexapy is a python package that is used by HA, but does not belong to HA
I also updated to v4.13.5 and the integration failed some time after doing a log-in, also for me…
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 https://github.com/alandtse/alexa_media_player/issues/2453
Did anybody on this thread has been able to fully solve their issue with this update?
See
alexapymerge request !391 which is already two weeks old now.That is coming from an
errorboxwindow 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 thaterrorboxwithout an error, but there really should not be anerrorboxwindow if everything succeeded.@r1si Elia,
I am using a python script which will issue a persistent notification if the
notify.alexa_mediaaction fails. Install HA’s Python Scripts Create these files in the<config>/python_scripts/folder:In Developer tools > Actions, execute
python_script.reload. Test the script in Dev Tools:python_script.notify_alexa_media. Once working, you can replace yournotify.alexa_media_xyzactions withpython_script.notify_alexa_media:Daniel is a god! @danielbrunt57
I removed the integration, rebooted, added the integration again, went into endless login loop, used the Daniel method to try to create a new account with the same email, it failed as planned, logged in again and this time got to the 2FA page. After this everything started working! It’s 3am and it took 3 hours to fix but it’s working!!! 😃
Daniel’s Method
I didnt want to be that guy 🤣🤣🤣 but, “its working for me” after doing that 😃
Reboot again, then try Daniel’s sequence
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.
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.
On Fri, Sep 13, 2024 at 8:46 AM deifel @.***> wrote:
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:
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:
My alexa media player integration was not working because of this error. I fixed up just by updating everything on my raspberry pi.
And them everything was back to normal.
Hope it helps
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.pywith 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.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. 🤷♂️
Active for months too. It worked till now.