首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Amazon Polly ProfileNotFound:找不到配置文件(管理员用户)

Amazon Polly ProfileNotFound:找不到配置文件(管理员用户)
EN

Stack Overflow用户
提问于 2017-04-21 02:38:54
回答 2查看 1.3K关注 0票数 1

我对Python非常陌生。我正在试用Amazon Polly Text to speech模块。我在Windows10上运行这个程序。我已经阅读了amazon文档,但我现在完全迷失了方向。对不起,我的英语不是很好。

我的代码如下。

代码语言:javascript
复制
    """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])

我这里有我的证件文件。(对此进行了编辑,使其不是真正的凭证)。在相同的文件夹中,它被保存为配置。我还在同一个文件夹中复制了名为config和boto.config的文件,希望我把名字弄错了。但无济于事。

代码语言:javascript
复制
[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

这是我得到的错误消息。

代码语言:javascript
复制
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
>>> 

有没有专家能告诉我该怎么做呢?

EN

回答 2

Stack Overflow用户

发布于 2018-01-23 11:40:07

您应该在~/.aws/config中进行设置

代码语言:javascript
复制
[profile adminuser]
aws_access_key_id = AKIAIO4GAFVCGZMTZ6WQ
aws_secret_access_key = /7KVymkCQbGKI5/E1ifdafsuVCciwOd1WiIImxA
票数 1
EN

Stack Overflow用户

发布于 2018-01-23 14:21:52

Boto3查找.aws/credentials文件或.boto.config文件进行身份验证。在windows机器上,您需要创建一个名为credentials或.boto.config的文件,并将该文件保存在位置C:\Users\USERNAME .aws\credentials。

文件内容将为

代码语言:javascript
复制
[adminuser]
aws_access_key_id = AKIAIO4GAFVCGZMTZ6WQ
aws_secret_access_key = /7KVymkCQbGKI5/E1ifdafsuVCciwOd1WiIImxA
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43527400

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档