[英]Failed to translate JSON in request error in Watson discovery query call
使用ibm-watson
Python SDK 版本 5.3.0 和以下代碼示例:
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}')
從服務器返回以下錯誤。
失敗的。 狀態碼 400:無法在請求中轉換 JSON:無法從字符串值(令牌“JsonToken.VALUE_STRING”)反序列化“scala.collection.immutable.List<java.lang.String>”類型的值
僅當指定了collections_ids
或table_results
時才會發生錯誤。
服務器告訴您發送給它的 JSON 與它期望處理的不匹配。
對於 API 請求, collections_ids
和table_results
的格式不正確。
根據API 文檔。
collections_ids
必須是一個列表。 所以更改為collections_ids=[collections]
table_results
需要一個 object。 正確使用table_results={ 'enabled': True }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.