Getting "error": "No text provided" when trying to post content to V2/Profile of personality insights API

334 Views Asked by At

I have deployed watson-developer-cloud/personality-insights-python module in to bluemix and created an APP in Bluemix. The link for my app is running absolutely fine. However, when I want to invoke /v2/profile api, with a post request I am getting an error. Here is the code I used in 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)

I keep getting this error.

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

If I change the url with out V2, then we are getting this error

b'{"code": 400, "error": "No text provided"}'

1

There are 1 best solutions below

1
On BEST ANSWER

Note that you should not be POSTing to that URL. If you develop a local application, you need to bind a Personality Insights service to a Bluemix app, and take the credentials from there (there is a URL, username and password that you can use -- the URL will start with https://gateway.watsonplatform.net/personality-insights/...). If I am wrong and this is a Bluemix app, then you should parse the VCAP_CREDENTIALS object and take the credentials from there -- see the sample applications in the documentation.

Then, once you get the right URL, please pay attention to that "The number of words ...." error. This means Personality Insights just cannot analyze a piece of text so small. It needs at least 100 words from its internal dictionary to match; and much beyond that, you need to provide at least 2000 or 3000 words to get an analysis with meaningful results. Good luck!