2017-07-25 67 views
0

我在調用IBM數據科學體驗中的模型後生成的API。 但是,當我使用POST調用API時,它發出錯誤「身份驗證失敗」。 現在的問題是,我已經使用IBM Watson機器學習服務提供的憑據,因爲該模型沒有提供任何憑據。來自Postman的IBM Data Science中的調用API

有人可以幫我在這種情況下如何進行?

回答

0

您需要使用Watson ML Service憑證生成令牌,並在發佈到您的得分URL時使用該令牌。您可以生成令牌像這樣(注:用戶名,密碼和service_path在你的沃森ML服務憑證):

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') 

當你打你的得分URL,你需要使用此令牌作爲Authorization頭:

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

有一個在下參考/樣品筆記本電腦的文檔的示例@https://console.bluemix.net/docs/services/PredictiveModeling/index.html#WMLgettingstarted