【问题标题】:Unable to access Watson Assistant via Python API - Error: Resource not found, Code: 404无法通过 Python API 访问 Watson Assistant - 错误:找不到资源,代码:404
【发布时间】:2020-01-09 05:00:47
【问题描述】:

我正在尝试使用 python 从 Watson 助手下载工作区。

assistant = assistant = AssistantV1(
    version='2019-02-28',
    iam_apikey='',
    url='https://gateway-fra.watsonplatform.net/assistant/api'
)
language = 'en'
workspace_id = "" #Skill Name:Poor mans disambiguation
#Frankfurt: https://api.eu-de.assistant.watson.cloud.ibm.com

response=assistant.list_workspaces().get_result()
print(json.dumps(response, indent=2))

list.wokpace 工作正常 - 低于示例输出

{
  "workspaces": [
    {
      "name": "1 - DEV ENGLISH",
      "language": "en",
      "metadata": {
        "api_version": {
          "major_version": "v1",
          "minor_version": "2019-02-28"
        }

但是当我尝试使用导出工作区时 response = assistant.get_workspace(workspace_id=workspace_id, export=True)

ApiException: Error: Resource not found, Code: 404 , X-global-transaction-id: a5e6e2ff76d987798c7c844b232f7f18

注意 - 我致力于工作区部署自动化。

希望我能在这里得到一些帮助。

【问题讨论】:

标签: ibm-cloud ibm-watson watson-assistant


【解决方案1】:

这里是下载工作区 JSON 助手的脚本

Api_key = ''
Skill_id = ''
Service_url = ''

start = time.time()
authenticator = IAMAuthenticator(Api_key)
assistant = AssistantV1(version='2019-02-28',authenticator = authenticator)
assistant.set_service_url(Service_url)
response=assistant.get_workspace(workspace_id=Skill_id).get_result()
end = time.time()
print("Execution time : ",end - start)

response = assistant.get_workspace(
    workspace_id=Skill_id, export=True).get_result()

【讨论】:

    【解决方案2】:

    要么是临时错误,要么您没有传入正确的工作区 ID。 get_workspace() API 是 V1 API 的一部分,需要工作区 ID,而不是技能 ID。

    我有Python tools based on V1 and V2,这是call to that get_workspace

    # Get and print a specific workspace by ID
    def getPrintWorkspace(workspaceID,exportWS):
        print(json.dumps(assistant.get_workspace(workspace_id=workspaceID,export=exportWS).get_result(), indent=2))
    

    它与文档中的内容和您的调用类似,因此您的代码应该一切正常。检查参数值。

    【讨论】:

      猜你喜欢
      • 2014-12-15
      • 2017-07-02
      • 1970-01-01
      • 2011-04-15
      • 1970-01-01
      • 1970-01-01
      • 2020-08-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多