0

I'm trying to call Personality Insights API from my Python web app but it always return the forbidden error 403 but when I call it from Postman Chrome extension it work successfully.

This is my python code:

def generatePersonalDescription(request):
    import requests
    from requests.auth import HTTPBasicAuth
    IBM_API_URL = "https://gateway.watsonplatform.net/personality-insights/api/v2/profile"
    top_level_url = "https://gateway.watsonplatform.net/personality-insights/api"
    username = "<user>"
    password = "<password>"

    JSON_OBJ = {'contentItems': [{'content' : 'strcontent' , 'contenttype': 'application/json','sourceid': 'blog123','language': 'en'}]}

    json_data = json.dumps(JSON_OBJ)

    resp = requests.get(IBM_API_URL, auth=(username, password))

    return HttpResponse(resp)

Is it possible that because the python is a server side and the API isn't allowed to accept requests from server side application?

herchu
  • 936
  • 7
  • 24
Deve
  • 181
  • 4
  • 14
  • Please make sure you do not ever publish your own credentials. They are tied to a paid account, and someone abusing from them might incur on changes to your credit card. – herchu Jul 11 '16 at 18:22

2 Answers2

1

It appears you are using HTTP GET method, while the Personality Insights profile API accepts POST. I am not sure this is the cause of HTTP 403 (it should not), but I would double check your credentials anyway. (By the way, never expose your credentials in a question here -- someone could use/abuse them!).

I would recommend you anyway to use the Python SDK where you can abstract from the API requests details. There are examples in the github page for watson-developer-cloud linked above. The package is even available in pip, so it should be simple to include it from any environment.

herchu
  • 936
  • 7
  • 24
1

I figure it out. The problem is that i'm using free pythonanywhere account which limit the users form sending requests to external servers to this whitelist. I need to upgrade my account to allow for unrestricted requests.

Deve
  • 181
  • 4
  • 14