当我使用适用于 Python 的 Watson Assistant 示例代码时,它在 Python 3.6.5 上完美运行。
但是我得到了错误:
TypeError: 'DetailedResponse' object is not subscriptable
当我尝试在 python 3.6.6 中执行代码时 它失败的命令是:
if response['output']['text']:
print(response['output']['text'][0])
如果我打印对象响应的类型,我会得到:
任何指点将不胜感激!
最佳答案
好的,找到答案了,希望对其他人有帮助:
现有代码:
if response['output']['text']:
print(response['output']['text'][0])
修改后的代码:
if response.result['output']['text']:
print(response.result['output']['text'][0])
关于python-3.x - 沃森 Python SDK : 'DetailedResponse' object is not subscriptable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52326202/