gpt4 book ai didi

python - 出现以下 TypeError : __init__() got an unexpected keyword argument 'iam_apikey'

转载 作者:行者123 更新时间:2023-12-01 00:30:12 25 4
gpt4 key购买 nike

在 Raspbian Buster 上运行。我按照 cloud.ibm.com api 文档上的说明进行了升级:

Installing collected packages: ibm-cloud-sdk-core, ibm-watson
Found existing installation: ibm-cloud-sdk-core 0.5.1
Uninstalling ibm-cloud-sdk-core-0.5.1:
Successfully uninstalled ibm-cloud-sdk-core-0.5.1
Found existing installation: ibm-watson 3.4.0
Uninstalling ibm-watson-3.4.0:
Successfully uninstalled ibm-watson-3.4.0
Successfully installed ibm-cloud-sdk-core-1.0.0 ibm-watson-4.0.1

脚本如下:

#!/usr/bin/python3
from ibm_watson import TextToSpeechV1
import json

text_to_speech = TextToSpeechV1(
iam_apikey='7XT8Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
url='https://stream.watsonplatform.net/text-to-speech/api'
)

with open('file.wav', 'wb') as audio_file:
audio_file.write(
...

同样,代码块仅包含第一行。没有真正的帮助。几乎相同的脚本在 Mint 18 上运行良好。

The actual error:
python3 watson.py
Traceback (most recent call last):
File "watson.py", line 7, in <module>
url='https://stream.watsonplatform.net/text-to-speech/api'
TypeError: __init__() got an unexpected keyword argument 'iam_apikey'

为了更好地衡量,我尝试使用 node.js 代码进行连接,但收到类似的错误,“缺少关键字 apikey”

感谢您的帮助。吉姆。

最佳答案

在您现在使用的版本 4 中,TextToSpeechV1 构造函数已更改为接受 authenticator 而不是 iam_apikey,以允许额外的身份验证机制。来自 migration docs :

Before

from ibm_watson import MyService

service = MyService(
iam_apikey='{apikey}',
url='{url}'
)

After (V4.0)

from ibm_watson import MyService
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator

authenticator = IAMAuthenticator('{apikey}')
service = MyService(
authenticator=authenticator
)
service.set_service_url('{url}')

在您的情况下,MyService 将是 TextToSpeechV1

关于python - 出现以下 TypeError : __init__() got an unexpected keyword argument 'iam_apikey' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58249587/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com