【问题标题】:Why do I keep getting 415 WatsonException: Error: unsupported media type in Python?为什么我不断收到 415 WatsonException:错误:Python 中不支持的媒体类型?
【发布时间】:2017-04-10 01:12:59
【问题描述】:

我正在尝试使用 Watson api 进行情绪分析。 代码非常简单。 但是为什么我总是收到这个错误??????

WatsonException: Error: unsupported media type, Code: 415

API 文档中没有关于此错误的信息。

from watson_developer_cloud import AlchemyLanguageV1
alchemy_language = AlchemyLanguageV1(url="https://gateway.watsonplatform.net/natural-language-understanding/api",
          username="xxx",
          password="xxx")
print(json.dumps(alchemy_language.sentiment(text="hehe")))

【问题讨论】:

  • 在构造 AlchemyLanguageV1 对象或调用sentiment() 方法时是否会出错?

标签: python json get httprequest ibm-watson


【解决方案1】:

请仔细查看sample code。首先,它使用 API 密钥构造了一个 AlchemyLanguageV1 对象,而不是登录名和密码,也许这就是原因?

【讨论】:

    【解决方案2】:

    我认为问题在于使用 Alchemy Language () 结束请求并添加 ,,然后添加 indent 参数。

    我认为这个参数是必需的,因为没有在请求中设置数据类型(例如application/json等)...

    并且文档中的所有请求都有参数indent=2

    我不确定,可能在 IBM 工作的人会确认。

    检查这个例子:

    import json
    from watson_developer_cloud import AlchemyLanguageV1
    
    alchemy_language = AlchemyLanguageV1(api_key='API_KEY')
    print(json.dumps(
      alchemy_language.sentiment(
        text='hehe'),
      indent=2))
    

    我通过测试文档链接得出了这个结论:here

    【讨论】:

      【解决方案3】:

      这是因为不再支持 AlchemyLanguageV1。 IBM 已将此组件集成到 Watson Natural Language Understanding。请参阅有关 Watson Natural Language Understanding 的文档。

      【讨论】:

        猜你喜欢
        • 2018-10-13
        • 2018-07-25
        • 2016-09-09
        • 2017-08-28
        • 2021-10-12
        • 2017-10-23
        • 2014-10-02
        • 2014-06-21
        • 2016-09-10
        相关资源
        最近更新 更多