【问题标题】:Watson Document ConversionWatson 文档转换
【发布时间】:2017-01-15 22:56:20
【问题描述】:

以下是我的 IBM Watson 文档转换代码。当我尝试在 Python 中运行脚本时,我不断收到以下错误消息。我在下面的代码中有我的用户名和密码 XXXX,但是我复制并粘贴了我的活动用户名和密码,所以我不知道是什么导致了凭证问题。任何帮助,将不胜感激。

watson_developer_cloud.watson_developer_cloud_service.WatsonException: 未经授权:由于凭据无效而拒绝访问

import json
from os.path import join, dirname
from watson_developer_cloud import DocumentConversionV1

document_conversion = DocumentConversionV1(
    username="XXXXXXXXXXX",
    password="XXXXXXXXXXXXXXXXX",
    version='2015-12-15')

with open(join(dirname(__file__), 'a16-23019_2nq.htm'),
      'r') as document:
    config = {'conversion_target':DocumentConversionV1.NORMALIZED_HTML}
    print(document_conversion.convert_document(
        document=document, config=config, media_type='text/html').content)

【问题讨论】:

    标签: python ibm-watson watson


    【解决方案1】:

    Drew,我不知道您是否正在使用您的 Bluemix 凭证,但如果是的话,它将不起作用,因为在这种情况下 IBM 请求 服务凭证

    如果您应该get“文档转换”内的服务凭据,如下图attached 所示。 如果您正在放置凭据但它仍然无法正常工作,请尝试代码 2。

    例子:

    document_conversion = DocumentConversionV1(
        username='67bxxx-xxxxx-xxxxxx-xxxxx-xxx',
        password='fWxxxxxxxxxxxxx',
        version='2016-02-09')
    

    或尝试使用 JSON 格式:

    document_conversion = DocumentConversionV1(
      username='{username}',
      password='{password}',
      version='2015-12-15'
    )
    

    第一步,点击链接:

    第 2 步,获取凭据并输入您的代码:

    如果您有更多问题,可以查看此 example 和此 link 以及来自 Watson 文档服务 (Python) 的示例,我也会尝试回答以帮助您。

    【讨论】:

      【解决方案2】:

      确保您的用户名和密码正确无误。这是一个常见的错误,你可以判断的方式是用户名会很长,密码会很短。

      【讨论】:

      • 简单的解决方案。密码/用户名倒退了。谢谢。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-09
      • 2021-12-11
      相关资源
      最近更新 更多