0

I am calling the API generated after deploying the model in IBM data science Experience. But while I am calling the API using POST then it is giving error "Authentication failed". Now problem is, I have used the credentials available in service of IBM Watson machine learning as the model does not provide any credential as such.

Can some one please help me how to proceed in this case?

1 Answers1

0

You need to generate a token using your Watson ML Service credentials and use that token when POSTing to your score URL. You can generate a token like so (note: username, password, and service_path are in your Watson ML Service credentials):

import urllib3, requests, json

headers = urllib3.util.make_headers(basic_auth='{}:{}'.format(username, password))
url = '{}/v3/identity/token'.format(service_path)
response = requests.get(url, headers=headers)
mltoken = json.loads(response.text).get('token')

When you hit your scoring URL you need to use this token as the Authorization header:

header = {'Authorization': 'Bearer ' + mltoken} 

There is an example in the docs under Reference / Sample notebooks @ https://console.bluemix.net/docs/services/PredictiveModeling/index.html#WMLgettingstarted

Sumit Goyal
  • 575
  • 3
  • 16
markwatsonatx
  • 3,391
  • 2
  • 21
  • 19
  • You may generate a token using the method. However when you curl request with the token with appropriate headers you will get a response. This however not the case if you were to use a REST client like postman. You will get a 405 method not allowed. – KosiB Jan 25 '19 at 03:38