Repository: alandtse/alexa_media_player

Issue #1028: Unknown error: Non-base32 digit found 
Created: 2020-11-29T23:10:14Z
Describe the bug
While running Home Assistant and installing the Alexa media player through HACS when configuring the app it throws the error Non-base32 digit found.
To Reproduce
Steps to reproduce the behavior:
1. Go to config ->integrations -> Add Intergration -- > Alexa Media Player
2. Fill all user credentials including the "FA Code + Built In 2FA App Key (this has been setup correctly my end) (Amazon region domain has been changed to amazon.co.uk
3. Advanced debugging unchecked
4. Included device, excluded device, seconds between scans + Cookies.txt data all stays as default
5. Click Submit
Expected behavior
To login to amazon.co.uk
Screenshots
If applicable, add screenshots to help explain your problem.
System details

Home-assistant (version):

Home Assistant 0.118.3


Hassio (Yes/No): (Please note you may have to restart hassio 2-3 times to load the latest version of alexapy after an update. This looks like a HA bug).
Restarted 3 times and still no change


alexa_media  (version from const.py or HA startup):


3.3.1 (latest)

alexapy (version from pip show alexapy or HA startup):

version 1.16.0

Amazon 2FA is enabled (y/n). We will not debug login issues if unanswered:
Yes all setup and enabled.

Logs
2020-11-29 23:03:25 DEBUG (MainThread) [custom_components.alexa_media.config_flow] Creating new login 2020-11-29 23:03:25 DEBUG (MainThread) [alexapy.alexalogin] Creating TOTP for 4**728 2020-11-29 23:03:25 WARNING (MainThread) [custom_components.alexa_media.config_flow] Unknown error: Non-base32 digit found 2020-11-29 23:03:27 DEBUG (MainThread) [custom_components.alexa_media.config_flow] Using existing login 2020-11-29 23:03:27 WARNING (MainThread) [custom_components.alexa_media.config_flow] Unknown error: Non-base32 digit found 2020-11-29 23:03:27 DEBUG (MainThread) [custom_components.alexa_media.config_flow] Using existing login 2020-11-29 23:03:27 WARNING (MainThread) [custom_components.alexa_media.config_flow] Unknown error: Non-base32 digit found 2020-11-29 23:03:28 DEBUG (MainThread) [custom_components.alexa_media.config_flow] Using existing login 2020-11-29 23:03:28 WARNING (MainThread) [custom_components.alexa_media.config_flow] Unknown error: Non-base32 digit found 2020-11-29 23:03:28 DEBUG (MainThread) [custom_components.alexa_media.config_flow] Using existing login 2020-11-29 23:03:28 WARNING (MainThread) [custom_components.alexa_media.config_flow] Unknown error: Non-base32 digit found
Additional context
Add any other context about the problem here.

Duplicate issue #1045: Error setting up alexa_media_player after 3.4.1 update.
Created: 2020-12-12T11:15:33Z
Describe the bug
After updating to 3.4.1 alexa_media_player no longer works and shows errors in the logs.
To Reproduce
Updated and now all entities are no longer available and errors in logs.
Expected behavior
Continue working
Screenshots
N/A
System details

Home-assistant (version): 0.118.5
Hassio (Yes/No): (Please note you may have to restart hassio 2-3 times to load the latest version of alexapy after an update. This looks like a HA bug). No
alexa_media  (version from const.py or HA startup): 3.4.1
alexapy (version from pip show alexapy or HA startup): 1.17.2
Amazon 2FA is enabled (y/n). We will not debug login issues if unanswered:  Y

Logs
Logger: alexapy.alexalogin
Source: /usr/local/lib/python3.8/site-packages/alexapy/alexalogin.py:157 
First occurred: 11:06:57 (1 occurrences) 
Last logged: 11:06:57

Error creating TOTP; ****** likely invalid

and
Logger: homeassistant.config_entries
Source: custom_components/alexa_media/__init__.py:250 
First occurred: 11:06:57 (1 occurrences) 
Last logged: 11:06:57

Error setting up entry apt@mac.com - amazon.co.uk for alexa_media
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/alexapy/alexalogin.py", line 154, in set_totp
    self.get_totp_token()
  File "/usr/local/lib/python3.8/site-packages/alexapy/alexalogin.py", line 173, in get_totp_token
    token: Text = self._totp.now()
  File "/usr/local/lib/python3.8/site-packages/pyotp/totp.py", line 44, in now
    return self.generate_otp(self.timecode(datetime.datetime.now()))
  File "/usr/local/lib/python3.8/site-packages/pyotp/otp.py", line 33, in generate_otp
    hasher = hmac.new(self.byte_secret(), self.int_to_bytestring(input), self.digest)
  File "/usr/local/lib/python3.8/site-packages/pyotp/otp.py", line 50, in byte_secret
    return base64.b32decode(self.secret, casefold=True)
  File "/usr/local/lib/python3.8/base64.py", line 231, in b32decode
    raise binascii.Error('Non-base32 digit found') from None
binascii.Error: Non-base32 digit found

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

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 236, in async_setup
    result = await component.async_setup_entry(hass, self)  # type: ignore
  File "/config/custom_components/alexa_media/__init__.py", line 250, in async_setup_entry
    AlexaLogin(
  File "/usr/local/lib/python3.8/site-packages/alexapy/alexalogin.py", line 100, in __init__
    self.set_totp(otp_secret.replace(" ", ""))
  File "/usr/local/lib/python3.8/site-packages/alexapy/alexalogin.py", line 160, in set_totp
    raise AlexapyPyotpInvalidKey(ex) from ex
alexapy.errors.AlexapyPyotpInvalidKey: Non-base32 digit found

Additional context
Was working correctly with the previous 3.4.0 version.

Closing comment (2020-12-12T19:23:04Z): Also Dupe of #1028.