Using the ibm-watson Python SDK version 5.3.0 with the following code example:
from ibm_watson import DiscoveryV2, ApiException
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
import json
url = 'https://api.eu-de.discovery.watson.cloud.ibm.com'
version = '2020-08-30'
apikey = '...'
project = '...'
collection = '...'
authenticator = IAMAuthenticator(apikey)
discovery = DiscoveryV2(version=version, authenticator=authenticator)
discovery.set_service_url(url)
try:
result = discovery.query(
project_id=project,
collection_ids=collection,
query='text:searchterm',
table_results=True
).get_result()
print(json.dumps(result, indent=2))
except ApiException as ex:
print(f'Failed. Status code {ex.code}: {ex.message}')
Returns the following error from the server.
Failed. Status code 400: Failed to translate JSON in request: Cannot deserialize value of type `scala.collection.immutable.List<java.lang.String>` from String value (token `JsonToken.VALUE_STRING`)
The error only occurs if collections_ids or table_results is specified.
The server is telling you that the JSON sent to it doesn't match what it expects to process.
The
collections_idsandtable_resultsare incorrectly formatted for the API request.As per the API documentation.
collections_idsmust be a list. So change tocollections_ids=[collections]table_resultsexpects an object. To correct usetable_results={ 'enabled': True }