I am trying to use Watson api for sentiment analysis. The code is quite simple. But why do I keep getting this error?????
WatsonException: Error: unsupported media type, Code: 415
Nothing about this error in API document.
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 :(得分:0)
Please look carefully on the sample code. First of all, it constructs an AlchemyLanguageV1 object using an API key, not login and password, maybe that is the cause?
答案 1 :(得分: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
答案 2 :(得分:0)
那是因为不再支持AlchemyLanguageV1。 IBM已将此组件集成到Watson Natural Language Understanding中。请参阅沃森自然语言理解的文档。