Core: Google TTS responding no 'group' attribute in log

Created on 21 Sep 2018  Â·  25Comments  Â·  Source: home-assistant/core

Home Assistant release with the issue:

Last working Home Assistant release (if known):
77.3

Operating environment (Hass.io/Docker/Windows/etc.):
RPi 3B+ running HASSBIAN

Component/platform:

TTS:
  - platform: google

Description of problem:
I am getting an error stating that no 'group' attribute from my log when activating any automation calling for google_tts_say

Problem-relevant configuration.yaml entries and (fill out even if it seems unimportant):

- id: '1534539041835'
  alias: "Google Todays Time/Temperature"
  trigger:
    platform: time
    at: '09:00:00'
  condition:
    condition: time
    weekday:
    - sun
    - mon
    - tue
    - wed
    - thu
    - fri
    - sat
  action:
  - service: media_player.turn_on
    entity_id:
    - media_player.family_room_speaker
    - media_player.living_room_speaker
  - delay: 00:00:02
  - service: media_player.volume_set
    data_template:
      entity_id:
      - media_player.family_room_speaker
      - media_player.living_room_speaker
      volume_level: '0.7'
  - delay: 00:00:02
  - service: tts.google_say
    entity_id:
    - media_player.family_room_speaker
    - media_player.living_room_speaker
    data_template:
      message: "The current time is {{ states('sensor.clock_time') }},
        Today's weather will be a {{ states('sensor.dark_sky_icon') }},
        with a high of {{ states('sensor.dark_sky_daytime_high_temperature') }} degrees."
      cache: false
  - delay: 00:00:15
  - service: media_player.turn_off
    entity_id:
    - media_player.family_room_speaker
    - media_player.living_room_speaker

Traceback (if applicable):

2018-09-20 09:56:10 ERROR (MainThread) [homeassistant.core] Error executing service <ServiceCall tts.google_say (c:d42417654cae40589b5a4472389d13da): cache=$
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/core.py", line 1117, in _event_to_service_call
    await service_handler.func(service_call)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/tts/__init__.py", line 134, in async_say_handle
    options=options
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/tts/__init__.py", line 300, in async_get_url
    engine, key, message, use_cache, language, options)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/tts/__init__.py", line 313, in async_get_tts_audio
    message, language, options)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/tts/google.py", line 83, in async_get_tts_audio
    token.calculate_token, part)
  File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
    future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
    raise self._exception
  File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/lib/python3.5/site-packages/gtts_token/gtts_token.py", line 28, in calculate_token
    seed = self._get_token_key()
  File "/srv/homeassistant/lib/python3.5/site-packages/gtts_token/gtts_token.py", line 62, in _get_token_key
     a = re.search("a\\\\x3d(-?\d+);", tkk_expr).group(1)
AttributeError: 'NoneType' object has no attribute 'group'

Additional information:
The automation worked before the release of 0.78 and the announcement of a the paid cloud service (not saying that is the issue)

Most helpful comment

@vladosam There are other issues when you want to use tts.goole_say with "Cast devices" (Google Home, Chromecast,...). So I wait untill that dust has settled down. I don't know if it is related to the cast issues, but I had to factory reset my Google Home today since it did not wake up when I said anything to it.

All 25 comments

16749

I have the same issue with "AttributeError: 'NoneType' object has no attribute 'group'"

the post above solved my 'group' error!! thank you @cicero200272

@rotcop4u2 , could you please elaborate how you solved it?

@Molodax i went to the post "https://github.com/home-assistant/home-assistant/issues/16749" and edited my gTTS-token.py file with this:

# -*- coding: utf-8 -*-
import calendar
import math
import time
import requests
import re


class Token:
    """ Token (Google Translate Token)
    Generate the current token key and allows generation of tokens (tk) with it
    Python version of `token-script.js` itself from translate.google.com
    """

    SALT_1 = "+-a^+6"
    SALT_2 = "+-3^+b+-f"

    def __init__(self):
        self.token_key = None

    def calculate_token(self, text, seed=None):
        """ Calculate the request token (`tk`) of a string
        :param text: str The text to calculate a token for
        :param seed: str The seed to use. By default this is the number of hours since epoch
        """

        if seed is None:
            seed = self._get_token_key()

        [first_seed, second_seed] = seed.split(".")

        try:
            d = bytearray(text.encode('UTF-8'))
        except UnicodeDecodeError:
            # This will probably only occur when d is actually a str containing UTF-8 chars, which means we don't need
            # to encode.
            d = bytearray(text)

        a = int(first_seed)
        for value in d:
            a += value
            a = self._work_token(a, self.SALT_1)
        a = self._work_token(a, self.SALT_2)
        a ^= int(second_seed)
        if 0 > a:
            a = (a & 2147483647) + 2147483648
        a %= 1E6
        a = int(a)
        return str(a) + "." + str(a ^ int(first_seed))

    def _get_token_key(self):
        if self.token_key is not None:
            return self.token_key

        response = requests.get("https://translate.google.com/")
        line = response.text.split('\n')[-1]
        tkk_expr = re.search(".*?(TKK=.*?;)W.*?", line).group(1)

        try:
            # Grab the token directly if already generated by function call
            result = re.search("\d{6}\.[0-9]+", tkk_expr).group(0)
        except AttributeError:
            # Generate the token using algorithm
            timestamp = calendar.timegm(time.gmtime())
            hours = int(math.floor(timestamp / 3600))
            a = re.search("a\\\\x3d(-?\d+);", tkk_expr).group(1)
            b = re.search("b\\\\x3d(-?\d+);", tkk_expr).group(1)

            result = str(hours) + "." + str(int(a) + int(b))

        self.token_key = result
        return result

    """ Functions used by the token calculation algorithm """
    def _rshift(self, val, n):
        return val >> n if val >= 0 else (val + 0x100000000) >> n

    def _work_token(self, a, seed):
        for i in range(0, len(seed) - 2, 3):
            char = seed[i + 2]
            d = ord(char[0]) - 87 if char >= "a" else int(char)
            d = self._rshift(a, d) if seed[i + 1] == "+" else a << d
            a = a + d & 4294967295 if seed[i] == "+" else a ^ d
        return a

I am on a RPi 3B+ so i ran in the terminal:

python -m compileall /usr/local/lib/python2.7/dist-packages/gtts_token/gtts_token.py /usr/local/lib/python2.7/dist-packages/gtts_token/gtts_token.pyc

result was no more error. I am not home at the moment to check if the speaker activated and read the message. I will do in the morning and edit my post. But it is showing a progress bar on my speaker on the FRONTEND and executing my automation to completion. So I can probably call that a fix, without even needing to hear it.

Thank you, @rotcop4u2 , now it is clear.
I'm using hassio, therefore, I will not be able to implement the fix in such way. Maybe it would be good to keep this issue open then?

@Molodax do you use samba at all for remote file access on your pc? or mac?

I use Samba, however, it seems that I have no access to /usr/ on hassio unfortunatelly

Same problem here, same error message. Also using hass.io so no hope for a DIY patch. Hope this gets resolved soon!

Same issue here. No patch possible in hass.io.
This combined with https://github.com/home-assistant/home-assistant/issues/16686 makes a real mess of tts.google_say and cast since 0.78....
Hope this gets fixed with highest priority. You have basically broken everything that works with tts.google and/or cast....

Tried rolling back to 0.77.3 but still not working. Guess I'll have to move over all my notifications to Alexa Media Player TTS for now.

Until it's fixed try this.
Unpack this zip file with two folders to custom_components folder
gtts_token.zip
i tested this in docker but this should work in hassio too.
And don't forget to restart homeassistant.

@rpitera @vladosam I also reverted back to 0.77.3 without any luck.
Afterwards I tried the fix of vladosam and everything works again now.

So on 0.77.3 with this fix, everything is up and running.

@dshokouhi Thanks for the info. I hope they fix the cast issue also in 0.78.3. For now I stick to 0.77.3

@ArnoutVerbeken the cast issue was fixed in 0.78.1 unless you still have the issue you need to provide your logs to the developers

I see you did provide info, ok seems like a few people still have issues. Personally I just used a config entry and let my devices get discovered on their own.

@vladosam - Giving it a try now. Will report back.

Update - Worked like a charm. I think I'm going to stay right here on 77.3 for a little while longer. See how things shake out since hass.io is still only at 0.78.1.

Thanks so much for the fix @vladosam and thanks @ArnoutVerbeken for the call out otherwise I might have missed it. Cheers to you both!

@rpitera This fix works with 0.78.1 so go ahead and update. ;)

@vladosam There are other issues when you want to use tts.goole_say with "Cast devices" (Google Home, Chromecast,...). So I wait untill that dust has settled down. I don't know if it is related to the cast issues, but I had to factory reset my Google Home today since it did not wake up when I said anything to it.

How exactly does one get to the gtts_token.py file to begin with?

Fixed via #16775

Issue recurring for me again on hassio 0.83.0

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/core.py", line 1177, in _event_to_service_call
    await service_handler.func(service_call)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/tts/__init__.py", line 137, in async_say_handle
    options=options
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/tts/__init__.py", line 306, in async_get_url
    engine, key, message, use_cache, language, options)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/tts/__init__.py", line 318, in async_get_tts_audio
    message, language, options)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/tts/google.py", line 83, in async_get_tts_audio
    token.calculate_token, part)
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.6/site-packages/gtts_token/gtts_token.py", line 28, in calculate_token
    seed = self._get_token_key()
  File "/usr/local/lib/python3.6/site-packages/gtts_token/gtts_token.py", line 57, in _get_token_key
    tkk_expr = re.search(".*?(TKK=.*?;)W.*?", line).group(1)
AttributeError: 'NoneType' object has no attribute 'group'

Issue recurring for me again on hassio 0.83.0

Traceback (most recent call last): File "/usr/local/lib/python3.6/site-packages/homeassistant/core.py", line 1177, in _event_to_service_call await service_handler.func(service_call) File "/usr/local/lib/python3.6/site-packages/homeassistant/components/tts/__init__.py", line 137, in async_say_handle options=options File "/usr/local/lib/python3.6/site-packages/homeassistant/components/tts/__init__.py", line 306, in async_get_url engine, key, message, use_cache, language, options) File "/usr/local/lib/python3.6/site-packages/homeassistant/components/tts/__init__.py", line 318, in async_get_tts_audio message, language, options) File "/usr/local/lib/python3.6/site-packages/homeassistant/components/tts/google.py", line 83, in async_get_tts_audio token.calculate_token, part) File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run result = self.fn(*self.args, **self.kwargs) File "/usr/local/lib/python3.6/site-packages/gtts_token/gtts_token.py", line 28, in calculate_token seed = self._get_token_key() File "/usr/local/lib/python3.6/site-packages/gtts_token/gtts_token.py", line 57, in _get_token_key tkk_expr = re.search(".*?(TKK=.*?;)W.*?", line).group(1) AttributeError: 'NoneType' object has no attribute 'group'

Same. I updated to v1.1.3 of gtts-token and that resolved the issue.

I'm still on 1.1.2 and I am getting the same issue again

On Thu, Nov 29, 2018, 7:26 PM Trejep <[email protected] wrote:

Issue recurring for me again on hassio 0.83.0

Traceback (most recent call last): File
"/usr/local/lib/python3.6/site-packages/homeassistant/core.py", line 1177,
in _event_to_service_call await service_handler.func(service_call) File
"/usr/local/lib/python3.6/site-packages/homeassistant/components/tts/__init__.py",
line 137, in async_say_handle options=options File
"/usr/local/lib/python3.6/site-packages/homeassistant/components/tts/__init__.py",
line 306, in async_get_url engine, key, message, use_cache, language,
options) File
"/usr/local/lib/python3.6/site-packages/homeassistant/components/tts/__init__.py",
line 318, in async_get_tts_audio message, language, options) File
"/usr/local/lib/python3.6/site-packages/homeassistant/components/tts/google.py",
line 83, in async_get_tts_audio token.calculate_token, part) File
"/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
result = self.fn(self.args, *self.kwargs) File
"/usr/local/lib/python3.6/site-packages/gtts_token/gtts_token.py", line 28,
in calculate_token seed = self._get_token_key() File
"/usr/local/lib/python3.6/site-packages/gtts_token/gtts_token.py", line 57,
in _get_token_key tkk_expr = re.search(".?(TKK=.?;)W.*?", line).group(1)
AttributeError: 'NoneType' object has no attribute 'group'

Same. I updated to v1.1.3 of gtts-token but that didn't resolve the issue.
Running in venv.

—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
https://github.com/home-assistant/home-assistant/issues/16766#issuecomment-443044965,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AkOsJkm4uMaY6OdSpSvU2yG0m9fBSWP0ks5u0HtLgaJpZM4Wzd3h
.

Was this page helpful?
0 / 5 - 0 ratings