为什么我总是得到415瓦异常:错误:Python中不支持的媒体类型?
我正在尝试使用Watson api进行情绪分析。 代码非常简单。 但为什么我总是犯这个错误为什么我总是得到415瓦异常:错误:Python中不支持的媒体类型?,python,json,get,httprequest,ibm-watson,Python,Json,Get,Httprequest,Ibm Watson,我正在尝试使用Watson api进行情绪分析。 代码非常简单。 但为什么我总是犯这个错误 WatsonException: Error: unsupported media type, Code: 415 API文档中没有关于此错误的任何信息 from watson_developer_cloud import AlchemyLanguageV1 alchemy_language = AlchemyLanguageV1(url="https://gateway.watsonplatform.
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")))
请仔细看这张桌子。首先,它使用API密钥而不是登录名和密码构造AlchemyLanguageV1对象,这可能是原因?我认为问题在于使用Alchemy Language
()
结束请求,并添加一个,
,然后添加缩进参数
我认为这个参数是必需的,因为它没有在请求中设置数据类型(例如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))
我通过测试文档链接得出了这个结论:这是因为不再支持AlchemyLanguageV1。IBM已将此组件集成到Watson自然语言理解中。有关Watson自然语言理解的信息,请参阅文档。在构造AlchemyLanguageV1对象或调用感悟()方法时,是否会出错?