2017-04-10 26 views
0

我正在尝试使用Watson API进行情感分析。代码很简单。 但为什么我一直得到这个错误?????为什么我一直得到415 WatsonException:错误:Python中不支持的媒体类型?

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"))) 
+0

当你构建AlchemyLanguageV1对象或调用sentiment()方法时,你会得到错误吗? – mekkanizer

回答

0

这是因为AlchemyLanguageV1不再支持。 IBM已将此组件整合到Watson Natural Language Understanding中。请参阅沃森自然语言理解文档。

0

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

0

我觉得问题是用Alchemy语言()的请求结束并添加一个,,之后添加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

相关问题