AttributeError: 'str' object has no attribute 'get' random stuff api python
AttributeError: 'str' object has no attribute 'get' random stuff api python
我正在尝试使用 Random stuff 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)
我认为这个 API 已被弃用:
Hey there, we have deprecated our old version and now we can only be operated through RapidApi. Kindly headover to https://api.pgamerx.com/new for more information
您应该切换到新版本,因为旧版本不再有效。
顺便说一下,这也是你得到错误的原因,因为对旧 API 的任何调用都会 return 上面的字符串,它显然没有 get()
函数.
我正在尝试使用 Random stuff 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)
我认为这个 API 已被弃用:
Hey there, we have deprecated our old version and now we can only be operated through RapidApi. Kindly headover to https://api.pgamerx.com/new for more information
您应该切换到新版本,因为旧版本不再有效。
顺便说一下,这也是你得到错误的原因,因为对旧 API 的任何调用都会 return 上面的字符串,它显然没有 get()
函数.