我已将watson-developer-cloud / personality-insights-python模块部署到bluemix中,并在Bluemix中创建了一个APP。我的应用程序的链接运行绝对正常。但是,当我想调用/ v2 / profile api时,发布一个post请求我收到错误。这是我在Python中使用的代码。
import requests, json
payload = {'id': 'my-id',
'userid': 'id-here',
'sourceid' : 'twitter',
'contenttype' : 'text/plain',
'language' : 'en',
'content' : 'text to analyse goes here'
}
input_data=json.dumps(payload);
r = requests.post("http://MY-APP.mybluemix.net/v2",
auth=("USERNAME", "PASSWORD"),
headers = {"content-type": "application/json"},
data=input_data)
print(r.content)
我一直收到这个错误。
b'{"help": "http://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/doc/personality-insights/#overviewInput", "error": "The number of words 1 is less than the minimum number of words required for analysis: 100", "code": 400}'
如果我更改了没有V2的网址,那么我们就会收到此错误
b'{"code": 400, "error": "No text provided"}'
答案 0 :(得分:3)
请注意,您不应该发布到该网址。如果您开发本地应用程序,则需要将Personality Insights服务绑定到Bluemix应用程序,并从那里获取凭据(您可以使用URL,用户名和密码 - URL将以{{3}开头})。如果我错了并且这是一个Bluemix应用程序,那么您应该解析VCAP_CREDENTIALS对象并从那里获取凭据 - 请参阅文档中的https://gateway.watsonplatform.net/personality-insights/..。
然后,一旦获得正确的URL,请注意“单词数量......”错误。这意味着Personality Insights无法分析如此小的文本。它需要至少100个内部字典才能匹配;除此之外,您还需要提供至少2000或3000个单词才能获得有意义结果的分析。祝你好运!