Search code examples
pythonpython-3.xibm-watsonwatson-discovery

Watson Discovery "Access is denied due to invalid credentials" - Python


I want to use IBM Watson Discovery Services but I am receiving an error message when trying to. The error message is: WatsonException: Unauthorized: Access is denied due to invalid credentials

import sys  
import os  
import json  
from watson_developer_cloud import DiscoveryV1  

discovery = DiscoveryV1(  
    username="{bbbaaaaa}",  
    password="{aaaaaabbbb}",  
    version="2017-09-01"
)  

qopts = {'query': 'enriched_text.entities.text:IBM'}  
my_query = discovery.query('system', 'news', qopts)  
print(json.dumps(my_query, indent=2))

Solution

  • Remove the { and the } from your username and password.

    It should now be

    discovery = DiscoveryV1(  
        username="aaaaabbbbbb",  
        password="bbbbbaaaaa",  
        version="2017-09-01"
    )