joe
joe

Reputation: 13

Amazon Polly ProfileNotFound: The config profile (adminuser) could not be found

I'm very new to Python. I'm trying out the Amazon Polly Text to speech module. I'm running this on Windows 10. Have read the amazon documentation but I'm quite lost at the moment.. Sorry my english isnt very good.

My Code is as follow.

    """Getting Started Example for Python 2.7+/3.3+"""
from boto3 import Session

from botocore.exceptions import BotoCoreError, ClientError

from contextlib import closing
import os
import sys
import subprocess
from tempfile import gettempdir
# Create a client using the credentials and region defined in the [adminuser]
# section of the AWS credentials file (~/.aws/credentials).
session = Session(profile_name="adminuser")
polly = session.client("polly")
try:
 # Request speech synthesis
    response = polly.synthesize_speech(Text="Hello world!", OutputFormat="mp3",
    VoiceId="Joanna")
except (BotoCoreError, ClientError) as error:
 # The service returned an error, exit gracefully
    print(error)
    sys.exit(-1)
# Access the audio stream from the response
if "AudioStream" in response:
 # Note: Closing the stream is important as the service throttles on the
 # number of parallel connections. Here we are using contextlib.closing to
 # ensure the close method of the stream object will be called automatically
 # at the end of the with statement's scope.
    with closing(response["AudioStream"]) as stream:
        output = os.path.join(gettempdir(), "speech.mp3")
    try:
         # Open a file for writing the output as a binary stream
         with open(output, "wb") as file:
             file.write(stream.read())
    except IOError as error:
         print(error)
         sys.exit(-1)
else:
 # The response didn't contain audio data, exit gracefully
    print("Could not stream audio")
    sys.exit(-1)
# Play the audio using the platform's default player
if sys.platform == "win32":
    os.startfile(output)
else:
 # the following works on Mac and Linux. (Darwin = mac, xdg-open = linux).
    opener = "open" if sys.platform == "darwin" else "xdg-open"
    subprocess.call([opener, output])

and i have my credential files here. (Edited this so it's not real credentials). In the same folder, it is saved as configuration. I also made copies of it called config, and boto.config in the same folder, in hopes i got the name wrong. But to no avail.

[Credentials]
aws_access_key_id = AKIAIO4GAFVCGZMTZ6WQ
aws_secret_access_key = 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

[adminuser]
aws_access_key_id = AKIAIO4GAFVCGZMTZ6WQ
aws_secret_access_key = /7KVymkCQbGKI5/E1ifdafsuVCciwOd1WiIImxA

This is the error message i get .

Traceback (most recent call last):
  File "C:/Users/joel/Desktop/New folder/test.py", line 11, in <module>
    session = Session(profile_name="adminuser")
  File "C:\Python27\lib\site-packages\boto3\session.py", line 80, in __init__
    self._setup_loader()
  File "C:\Python27\lib\site-packages\boto3\session.py", line 120, in _setup_loader
    self._loader = self._session.get_component('data_loader')
  File "C:\Python27\lib\site-packages\botocore\session.py", line 701, in get_component
    return self._components.get_component(name)
  File "C:\Python27\lib\site-packages\botocore\session.py", line 897, in get_component
    self._components[name] = factory()
  File "C:\Python27\lib\site-packages\botocore\session.py", line 181, in <lambda>
    lambda:  create_loader(self.get_config_variable('data_path')))
  File "C:\Python27\lib\site-packages\botocore\session.py", line 265, in get_config_variable
    elif self._found_in_config_file(methods, var_config):
  File "C:\Python27\lib\site-packages\botocore\session.py", line 286, in _found_in_config_file
    return var_config[0] in self.get_scoped_config()
  File "C:\Python27\lib\site-packages\botocore\session.py", line 358, in get_scoped_config
    raise ProfileNotFound(profile=profile_name)
ProfileNotFound: The config profile (adminuser) could not be found
>>> 

any experts out there to tell me what I should do roughly?

Upvotes: 1

Views: 1727

Answers (2)

Shantanu
Shantanu

Reputation: 2346

Boto3 looks for either .aws/credentials file or .boto.config file for authentication. On windows machine you need to create a file called credentials OR .boto.config and keep the file at this location C:\Users\USERNAME .aws\credentials.

File content would be

[adminuser]
aws_access_key_id = AKIAIO4GAFVCGZMTZ6WQ
aws_secret_access_key = /7KVymkCQbGKI5/E1ifdafsuVCciwOd1WiIImxA

Upvotes: 1

duyvk
duyvk

Reputation: 66

you should set in ~/.aws/config

[profile adminuser]
aws_access_key_id = AKIAIO4GAFVCGZMTZ6WQ
aws_secret_access_key = /7KVymkCQbGKI5/E1ifdafsuVCciwOd1WiIImxA

Upvotes: 1

Related Questions