我试图使用随机物 api制作一个AI聊天机器人,每当我尝试创建一个聊天机器人时,我总是会得到这个错误(我使用replit.com来托管):
Traceback (most recent call last):
File "main.py", line 5, in <module>
response = client.get_ai_response("Hi there!")
File "/home/runner/ChatBot/venv/lib/python3.8/site-packages/randomstuff/client.py", line 254, in get_ai_response
message=response[0].get('response'),
AttributeError: 'str' object has no attribute 'get'
守则如下:
import randomstuff
client = randomstuff.Client(api_key="xxx")
response = client.get_ai_response("Hi there!")
print(response.message)
发布于 2022-04-18 05:26:38
我相信这个API已被否决:
嘿,我们反对我们的旧版本,现在我们只能通过RapidApi操作。如需更多信息,请访问https://api.pgamerx.com/new。
您应该切换到新版本,因为旧版本不再起作用了。
顺便说一句,这也是您获得错误的原因,因为对旧API的任何调用都会返回上面的字符串,而该字符串显然没有get()
函数。
https://stackoverflow.com/questions/71907838
复制相似问题