Watson Python SDK: 'DetailedResponse' object is not subscriptable

Viewed 2154

When I use the Watson Assistant sample code for Python, it works perfectly on python 3.6.5.

But I get the error:

TypeError: 'DetailedResponse' object is not subscriptable

when I try to execute the code in python 3.6.6 The command it is failing on is:

if response['output']['text']:
print(response['output']['text'][0])

and if I print the type of the object response, I get:

Any pointers will be appreciated!

1 Answers

Ok, found the answer, I hope it helps others:

The existing code:

if response['output']['text']:
    print(response['output']['text'][0])

Modified code:

if response.result['output']['text']:
    print(response.result['output']['text'][0])
Related