pythonibm-watsonwatson-assistantwatson-discoveryibm-cloud-functions

Can we call other Watson services(like assistant, discovery etc.,) from 'ibm cloud functions' using python( ibm_watson sdk)?


I am trying to call watson discovery service in 'ibm cloud function' where only older version python package('watson_developer_cloud') was installed. I am getting the below error when list_environments() method of discovery is called:

import json
from watson_developer_cloud import DiscoveryV1 

discovery = DiscoveryV1(
    version= version,
    iam_apikey = apikey,
    iam_url = url
)

discovery.list_environments()

error:

---------------------------------------------------------------------------
WatsonApiException                        Traceback (most recent call last)
<ipython-input-28-46be562e6568> in <module>()
     13 )
     14 
---> 15 discovery.list_environments()

4 frames
/usr/local/lib/python3.6/dist-packages/watson_developer_cloud/iam_token_manager.py in request(self, method, url, headers, params, data, **kwargs)
     32             from .watson_service import WatsonApiException, get_error_message
     33             error_message = get_error_message(response)
---> 34             raise WatsonApiException(response.status_code, message=error_message, httpResponse=response)
     35 
     36     def get_token(self):

WatsonApiException: Error: Not Found, Code: 404

Is there anyway for installing latest version packages in 'ibm cloud function'? or any workaround for handling the above error?


Solution

  • Looking at the code snippet above I believe the issue is that you are using the iam_key, and iam_url elements. These would inform Watson to contact the IAM service to then authenticate you. You may wish to try replacing iam_key / iam_url with username / password, which was more common with the Watson SDK level you are using. If you have just an apikey, you can try using "apikey" as the username and the apikey as the password.
    You could test if you have the right values via curl or postman. If work then try them in you python code. You could also test your code outside the ibm cloud function, via a command line, again checking its all works, and then move to the cloud function.