Python IBM Watson NLU情绪分析-类型错误:无法转换dic

Python IBM Watson NLU情绪分析-类型错误:无法转换dic,python,typeerror,ibm-watson,Python,Typeerror,Ibm Watson,使用下面的代码,我得到了错误消息 TypeError:无法将字典更新序列元素#0转换为序列 使用的代码如下所示: import watson_developer_cloud as WDC import watson_developer_cloud.natural_language_understanding.features.v1 as nluFeatures #from wdc_config import nlu_config nlu = WDC.NaturalLanguageUnderst

使用下面的代码,我得到了错误消息

TypeError:无法将字典更新序列元素#0转换为序列

使用的代码如下所示:

import watson_developer_cloud as WDC
import watson_developer_cloud.natural_language_understanding.features.v1 as nluFeatures
#from wdc_config import nlu_config

nlu = WDC.NaturalLanguageUnderstandingV1('2017-02-27',username='myusernamehere',password='mypasswordhere')

data = ([1, "I've seen things you people wouldn't believe. Attack ships on fire off the shoulder of Orion. I watched C-beams glitter in the dark near the Tannhauser Gate. All those moments will be lost in time, like tears in rain. Time to die."])


def nlu_analyze():
    response = nlu.analyze(text=data,features=[nluFeatures.Keywords(),nluFeatures.Entities(),nluFeatures.Categories(),nluFeatures.Emotion(),nluFeatures.Sentiment()])
    return response

response = nlu_analyze()
print(response["keywords"])
print(response["entities"])
print(response["categories"])
print(response["emotion"])
print(response["sentiment"])
为什么会出现这个错误


解决了的 多亏了chughts,这个问题才得以解决

import watson_developer_cloud as WDC
from watson_developer_cloud.natural_language_understanding_v1 import Features, KeywordsOptions, EntitiesOptions, CategoriesOptions, EmotionOptions, SentimentOptions


nlu = WDC.NaturalLanguageUnderstandingV1('2017-02-27',username='yourusername',password='yourpassword')

data = ("I've seen things you people wouldn't believe. Attack ships on fire off the shoulder of Orion. I watched C-beams glitter in the dark near the Tannhauser Gate. All those moments will be lost in time, like tears in rain. Time to die.")

def nlu_analyze():
    response = nlu.analyze(text=data, features=Features(keywords=KeywordsOptions(), entities=EntitiesOptions(), categories=CategoriesOptions(), emotion=EmotionOptions(), sentiment=SentimentOptions()))

return response

response = nlu_analyze()
print(response["keywords"])
print(response["entities"])
print(response["categories"])
print(response["emotion"])
print(response["sentiment"])

我认为问题在于你导入的功能

import watson_developer_cloud.natural_language_understanding.features.v1 as nluFeatures
根据API文件的规定—— 应该是

from watson_developer_cloud.natural_language_understanding_v1 \
  import Features, KeywordsOptions, EntitiesOptions, CategoriesOptions, EmotionOptions, SentimentOptions

将成为

   response = nlu.analyze(text=data,features=Features(keywords=KeywordsOptions(),entities=EntitiesOptions(),categories=CategoriesOptions(),emotion=EmotionOptions(),sentiment=SentimentOptions()))
   response = nlu.analyze(text=data,features=Features(keywords=KeywordsOptions(),entities=EntitiesOptions(),categories=CategoriesOptions(),emotion=EmotionOptions(),sentiment=SentimentOptions()))