Search code examples
python-2.7ibm-cloudibm-watson

Issue using set_detailed_response - ibm watson python sdk


When changing from version 2.10.4 of the IBM-cloud python SDK to the new 3.0.4 version I am no longer able to use set_detailed_response(False)

Using the IBM_watson python SDK to utilise watson assistant, text to speech, speech to text and visual recognition services. When the SDK was updated to version 2.0 the default response for all methods was changed to DetailedResponse (https://pypi.org/project/ibm-watson/#changes-for-v20). An issue with this DetailedResponse is that it is not iterable which is needed for my situation. Fortunately, the SDK provides a way to change this using set_detailed_response(False) (https://pypi.org/project/ibm-watson/#parsing-http-response-info)

e.g

from ibm_watson import VisualRecognitionV3

visualrecognition = VisualRecognitionV3(
    username='xxx',
    password='yyy',
    url='<url_as_per_region>',
    version='version',
    iam_apikey='apikey')

visualrecognition.set_detailed_response(False)

But since updating to version 3.0.4, I get the following error:

AttributeError: 'VisualRecognitionV3' object has no attribute 'set_detailed_response'


Solution

  • To have the old behavior, i.e., to get just the regular response, that changelog section you are referencing suggests to apply get_result() to the response.

    print(response.get_result())
    

    I haven't tested it with VR, but it works with my Watson Assistant and Discovery services.