home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.56k stars 30.74k forks source link

Unable to setup Amazon Polly TTS #26287

Closed SeafireGit closed 5 years ago

SeafireGit commented 5 years ago

Home Assistant release with the issue:

0.97.2

Last working Home Assistant release (if known):

Operating environment (Hass.io/Docker/Windows/etc.): Hassbian

Component/platform: https://www.home-assistant.io/components/amazon_polly/

Description of problem: Unable to set up Amazon polly

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

tts:
  - platform: amazon_polly
    aws_access_key_id: 'XXX'
    aws_secret_access_key: 'XXX'
    region_name: 'eu-west-3'
    voice: Celine

Traceback (if applicable):

2019-08-30 08:17:50 INFO (SyncWorker_2) [homeassistant.loader] Loaded amazon_polly from homeassistant.components.amazon_polly
2019-08-30 08:17:53 INFO (MainThread) [homeassistant.setup] Setting up tts
2019-08-30 08:17:56 DEBUG (SyncWorker_2) [botocore.loaders] Loading JSON file: /srv/homeassistant/lib/python3.7/site-packages/botocore/data/polly/2016-06-10/service-2.json
2019-08-30 08:17:56 DEBUG (SyncWorker_2) [botocore.hooks] Event creating-client-class.polly: calling handler <function add_generate_presigned_url at 0x656a3a98>
2019-08-30 08:17:56 DEBUG (SyncWorker_2) [botocore.endpoint] Setting polly timeout as (60, 60)
2019-08-30 08:17:56 DEBUG (SyncWorker_2) [botocore.client] Registering retry handlers for service: polly
2019-08-30 08:17:56 DEBUG (SyncWorker_2) [botocore.hooks] Event before-parameter-build.polly.DescribeVoices: calling handler <function generate_idempotent_uuid at 0x656c5a08>
2019-08-30 08:17:56 DEBUG (SyncWorker_2) [botocore.hooks] Event before-call.polly.DescribeVoices: calling handler <function inject_api_version_header_if_needed at 0x656c8780>
2019-08-30 08:17:56 DEBUG (SyncWorker_2) [botocore.endpoint] Making request for OperationModel(name=DescribeVoices) with params: {'url_path': '/v1/voices', 'query_string': {}, 'method': 'GET', 'headers': {'User-Agent': 'Boto3/1.9.16 Python/3.7.3 Linux/4.19.66-v7+ Botocore/1.12.219'}, 'body': b'', 'url': 'https://polly.eu-west-3.amazonaws.com/v1/voices', 'context': {'client_region': 'eu-west-3', 'client_config': <botocore.config.Config object at 0x63f2e690>, 'has_streaming_input': False, 'auth_type': None}}
2019-08-30 08:17:56 DEBUG (SyncWorker_2) [botocore.hooks] Event request-created.polly.DescribeVoices: calling handler <bound method RequestSigner.handler of <botocore.signers.RequestSigner object at 0x63f2ed10>>
2019-08-30 08:17:56 DEBUG (SyncWorker_2) [botocore.hooks] Event choose-signer.polly.DescribeVoices: calling handler <function set_operation_specific_signer at 0x656c5978>
host:polly.eu-west-3.amazonaws.com
20190830/eu-west-3/polly/aws4_request
2019-08-30 08:17:56 DEBUG (SyncWorker_2) [botocore.endpoint] Sending http request: <AWSPreparedRequest stream_output=False, method=GET, url=https://polly.eu-west-3.amazonaws.com/v1/voices, headers={'User-Agent': b'Boto3/1.9.16 Python/3.7.3 Linux/4.19.66-v7+ Botocore/1.12.219', 'X-Amz-Date': b'20190830T071756Z', 'Authorization': b'AWS4-HMAC-SHA256 Credential=XXX/20190830/eu-west-3/polly/aws4_request, SignedHeaders=host;x-amz-date, Signature=XXX'}>
2019-08-30 08:17:56 DEBUG (SyncWorker_2) [botocore.hooks] Event needs-retry.polly.DescribeVoices: calling handler <botocore.retryhandler.RetryHandler object at 0x63f20910>
2019-08-30 08:17:56 ERROR (MainThread) [homeassistant.components.tts] Error setting up platform: amazon_polly
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/tts/__init__.py", line 126, in async_setup_platform
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/amazon_polly/tts.py", line 177, in get_engine
    all_voices_req = polly_client.describe_voices()

Additional information:

Hello, I am unable to make Amazon Polly TTS work. I tried to uninstall and reinstall boto3 (pip3 [un]install boto3) without success neither.

SeafireGit commented 5 years ago

Problem seems to be somewhere here : https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/amazon_polly/tts.py

between line 142 and 184, but I can't figure out what it is.

springstan commented 5 years ago

I think that the parameters aws_access_key_id, aws_secret_access_key and region_name are expecting a normal string. So try to configure it without quotation marks surrounding the actual value.

SeafireGit commented 5 years ago

I removed the quote for each parameter but I still get the same error. :(

springstan commented 5 years ago

It seems to fail here File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/amazon_polly/tts.py", line 177, in get_engine all_voices_req = polly_client.describe_voices(), which is shortly after creating your polly client. So I would suggest that there is some kind of issue when creating your client. Maybe your credentials are not working properly somehow.

Have you tried to test your credentials with the official Amazon python package boto3? If not try something along the lines of:

import boto3
polly_client = boto3.client(
    'polly',
    aws_access_key_id='YOUR ACCESS_KEY',
    aws_secret_access_key='YOUR SECRET_KEY',
    region_name='YOUR REGION_NAME'
)
all_voices_req = polly_client.describe_voices()

Just to make sure that your credentials are working as they should be :)

If you get any errors just let me know.

SeafireGit commented 5 years ago

I double check my credential and they were right. So I tried the credential directly with boto3, and it indeed didn't work. I regenerate new one on AWS website and it works now !

For whatever reason, the first generated secret key ( mk/RRUeZL[...]bekt6ic7X6xOPs2A2N now deactivated) had a '/' in it, so I suppose boto is not able to deal with / in the secret key. This is the only difference I can see. I'm not sure if there is a way to make the error more explicit in HA logs, as the error raised by boto is : botocore.exceptions.ClientError: An error occurred (InvalidSignatureException) when calling the DescribeVoices operation: The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.

Thanks a lot Springstan for your help, and sorry for the inconvenience.

springstan commented 5 years ago

That is great to hear! Yeah it seems like boto does not handle / correctly. Please open an issue on boto's repo so they are aware and can fix this issue for future users.

Of course! Do not be sorry for that we are a community after all, who help each other out :) And by the way do not forget to close this issue here.

SeafireGit commented 5 years ago

Issue solved.