Echo Devices (Alexa) as Media Player - Testers Needed

Any help with this?

Error while setting up platform alexa
Traceback (most recent call last):
File “/usr/local/lib/python3.6/site-packages/urllib3/connection.py”, line 171, in _new_conn
(self._dns_host, self.port), self.timeout, **extra_kw)
File “/usr/local/lib/python3.6/site-packages/urllib3/util/connection.py”, line 56, in create_connection
for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
File “/usr/local/lib/python3.6/socket.py”, line 745, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name does not resolve

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py”, line 600, in urlopen
chunked=chunked)
File “/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py”, line 343, in _make_request
self._validate_conn(conn)
File “/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py”, line 849, in _validate_conn
conn.connect()
File “/usr/local/lib/python3.6/site-packages/urllib3/connection.py”, line 314, in connect
conn = self._new_conn()
File “/usr/local/lib/python3.6/site-packages/urllib3/connection.py”, line 180, in _new_conn
self, “Failed to establish a new connection: %s” % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.VerifiedHTTPSConnection object at 0x7565b190>: Failed to establish a new connection: [Errno -2] Name does not resolve

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/usr/local/lib/python3.6/site-packages/requests/adapters.py”, line 445, in send
timeout=timeout

I deleted the entire pycache folder, started with a fresh alexa.py download, did the login/logout/switch account sequence… still same exact error.

I am running in docker - homeassistant/home-assistant:latest
last update 25 July 2018

I am happy to run custom debugging code… thanks for your help

about that alexa.py download, I did that too, and somehow the file that I got (still named alexa.py) had some strange lines added to it. So I deleted the “downloaded” alexa.py, created an empty file called alexa.py, and opened the alexa.py from github, choosed “raw”, and copy/paste the contents into my file.
Only then, the 2 files (the one from github, and mine) were identical.
Needless to say that the “odd” alexa.py threw a number of errors … until I replaced it … did you downloaded or opened and copy / paste the contents ?

Yeah - i did a wget. and ive repeated it several times, and does a ‘diff’ between each version - no changes to speak of! so odd.

wget https://raw.githubusercontent.com/keatontaylor/custom_components/master/media_player/alexa.py

I just wanted to jump in and say that everything is working as described for me.

I’m running HA in Docker on Ubuntu with the alexa.py in my custom_components/media_player folder and

media_player:
  - platform: alexa
    email: !secret alexa_user
    password: !secret alexa_password
    url: amazon.ca

in my configuration.yaml

Great work everyone, I’m excited to see the next versions when they drop!

no luck running on my Hassio

This is what i got in config file

media_player:
  - platform: alexa
    email: “my id”
    password: “mypassword”
    url: “amazon.in”

and this is the error, any one can help?

Testing configuration at /config
ERROR:homeassistant.scripts.check_config:BURB
Traceback (most recent call last):
File “/usr/local/lib/python3.6/site-packages/homeassistant/scripts/check_config.py”, line 207, in check
res[‘components’] = check_ha_config_file(hass)
File “/usr/local/lib/python3.6/site-packages/homeassistant/scripts/check_config.py”, line 372, in check_ha_config_file
platform = loader.get_platform(hass, domain, p_name)
File “/usr/local/lib/python3.6/site-packages/homeassistant/loader.py”, line 59, in get_platform
return get_component(hass, PLATFORM_FORMAT.format(domain, platform))
File “/usr/local/lib/python3.6/site-packages/homeassistant/loader.py”, line 87, in get_component
module = importlib.import_module(path)
File “/usr/local/lib/python3.6/importlib/init.py”, line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File “”, line 994, in _gcd_import
File “”, line 971, in _find_and_load
File “”, line 955, in _find_and_load_unlocked
File “”, line 665, in _load_unlocked
File “”, line 674, in exec_module
File “”, line 781, in get_code
File “”, line 741, in source_to_code
File “”, line 219, in _call_with_frames_removed
File “/config/custom_components/media_player/alexa.py”, line 7

^
SyntaxError: invalid syntax
Fatal error while loading config: invalid syntax (alexa.py, line 7)
Failed config
General Errors:
- invalid syntax (alexa.py, line 7)
Successful config (partial)

Get rid of all the quotes … this is how mine looks like, and it’s working well :

media_player:
  - platform: panasonic_viera
    name: Panasonic TV
    host: 192.168.1.88
    mac: 48:A9:D2:70:AC:94
  - platform: alexa
    host: 192.168.1.151
    email: !secret media_player_alexa_email
    password: !secret media_player_alexa_password
    url: amazon.com

Keep in mind, that at this time, it seems that everybody using Docker is fine, while the others are stomped by errors at every step …

1 Like

Hi! I am testing this on my Hassio (Docker) 0.74.2 and are getting this error:

  • platform: alexa
    email: [email protected]
    password: mypass
    url: amazon.com

    Error doing job: Future exception was never retrieved
    Traceback (most recent call last):
    File “/usr/local/lib/python3.6/concurrent/futures/thread.py”, line 56, in run
    result = self.fn(*self.args, **self.kwargs)
    File “/config/custom_components/media_player/alexa.py”, line 120, in
    track_utc_time_change(hass, lambda now: update_devices(), second=30)
    File “/usr/local/lib/python3.6/site-packages/homeassistant/util/init.py”, line 318, in wrapper
    result = method(*args, **kwargs)
    File “/usr/local/lib/python3.6/site-packages/homeassistant/util/init.py”, line 318, in wrapper
    result = method(*args, **kwargs)
    File “/config/custom_components/media_player/alexa.py”, line 129, in update_devices
    devices = devices.json()[‘devices’]
    File “/usr/local/lib/python3.6/site-packages/requests/models.py”, line 896, in json
    return complexjson.loads(self.text, **kwargs)
    File “/usr/local/lib/python3.6/site-packages/simplejson/init.py”, line 518, in loads
    return _default_decoder.decode(s)
    File “/usr/local/lib/python3.6/site-packages/simplejson/decoder.py”, line 370, in decode
    obj, end = self.raw_decode(s)
    File “/usr/local/lib/python3.6/site-packages/simplejson/decoder.py”, line 400, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
    simplejson.errors.JSONDecodeError: Expecting value: line 8 column 1 (char 7)

The setting in media_player no quote ’ and no double quote "

media_player:
  - platform: alexa
    email: my id
    password: mypassword
    url: amazon.in
1 Like

I think this is the error most of us are still getting. Any updates on this? It seems, that the login process still fails.

Regards

I just submitted a PR to @keatontaylor that resolved it on my system (virtualenv based). For those who are adventurous you can try it before it’s merged in.

I’ve tried it and still get the same error with amazon.co.uk

I tried that in addition to deauthorizing ALL of my Amazon devices, web sessions, and apps.

Still getting

Error doing job: Task exception was never retrieved

Traceback (most recent call last):
  File "/config/custom_components/media_player/alexa.py", line 98, in setup_platform_callback
    login.login(captcha=callback_data.get('captcha'))
  File "/config/custom_components/media_player/alexa.py", line 557, in login
    post_resp_json = post_resp.json()['devices']
  File "/usr/local/lib/python3.6/site-packages/requests/models.py", line 896, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/simplejson/__init__.py", line 518, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.6/site-packages/simplejson/decoder.py", line 370, in decode
    obj, end = self.raw_decode(s)
  File "/usr/local/lib/python3.6/site-packages/simplejson/decoder.py", line 400, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
simplejson.errors.JSONDecodeError: Expecting value: line 8 column 1 (char 7)

Thanks @alandtse. How can I download/merge/get that working version?

You can copy code from alexa.py

Ok thank you. I tried this code now and get the following exception after entering the captcha:

2018-08-02 17:12:07 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved

Traceback (most recent call last):
  File "/config/custom_components/media_player/alexa.py", line 98, in setup_platform_callback
    login.login(captcha=callback_data.get('captcha'))
  File "/config/custom_components/media_player/alexa.py", line 557, in login
    post_resp_json = post_resp.json()['devices']
  File "/usr/local/lib/python3.6/site-packages/requests/models.py", line 896, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/simplejson/__init__.py", line 518, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.6/site-packages/simplejson/decoder.py", line 370, in decode
    obj, end = self.raw_decode(s)
  File "/usr/local/lib/python3.6/site-packages/simplejson/decoder.py", line 400, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
simplejson.errors.JSONDecodeError: Expecting value: line 8 column 1 (char 7)

So the code expects a json response here but still gets an HTML site, which can’t be decoded as json. Therefor I think, that its still the login which fails…

@deadwood83 @lweberru
I added some debugging code. If you have Logger on DEBUG mode, do you see any lines like this?

Aug 02 02:44:33 raspberrypi hass[8911]: 2018-08-02 02:44:33 DEBUG (MainThread) [custom_components.media_player.alexa] Log in failure.

Aug 02 02:44:55 raspberrypi hass[8911]: 2018-08-02 02:44:55 DEBUG (MainThread) [custom_components.media_player.alexa] Succesfully logged in. 

To turn on DEBUG mode, you’d need to edit your configuration.yaml:

logger:
  logs:
    custom_components.media_player.alexa: debug

I also have another version of the file in my debug branch that allows more extensive debugging, but it will require the ability to write to /tmp/login.txt and /tmp/get_devices.txt to dump the HTML files causing the exception. If you understand how to pull /tmp/ off your system and want to test, please grab that version.

(PLEASE NOTE: I’m not providing step by step instructions for now as this stage of debugging requires a bit more technical knowledge of your *nix systems/HTML and those files may have your personal info in it if it’s actually logging in.) If you generate the .txt files, please remove anything you don’t want me to see and DM me separately so it’s not public.

For those experiencing the JSONDecode issue, I think the issue is that amazon is not only asking for a captcha but also asking for an email verification link (I ran into this during my testing over the last week)

So essentially it isn’t logging in. Working on getting this fixed soon.

Any ideas for my error?

  1. I have the media_player set up
  2. captcha is working fine
  3. all my echo dots show up in HA
    so all three of these are fine

But most say stand by, and if I type something in on HA my dot says “Sorry text to speech to only be called with a media player alexa tts service”, so something is working. And if I try and add an automation I get the error…

Error loading /config/configuration.yaml: while scanning for the next token
found character '\t' that cannot start any token
  in "/config/automations.yaml", line 10, column 1

Any ideas? I have tried starting over again but it give the same error. It worked once but after a restart I started having this issue.

For those running into this issue:

bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library?

Try amending alexa.py lines 539 and 522:

soup = BeautifulSoup(html , 'lxml')
to

soup = BeautifulSoup(html , 'html.parser')

and 539:

    post_soup = BeautifulSoup(post_resp.content , 'lxml')

to

    post_soup = BeautifulSoup(post_resp.content , 'html.parser')

You may need to install html.parser using:

sudo pip3 install html.parser