如何解决 NLU Watson API 中的内容为空错误?

2023-12-21

我正在文件中流式传输推文tweet.txt并使用另一个 python 脚本,我正在阅读推文并将它们发送到 Watson。有时,会产生错误:

回溯(最近一次调用最后一次):文件“readingTweets.py”,第 44 行, 在 language='en' 文件 "/usr/local/lib/python2.7/dist-packages/watson_developer_cloud/natural_language_understanding_v1.py", 第 173 行,在分析中 method='POST'、url=url、params=params、json=data、accept_json=True) 文件 “/usr/local/lib/python2.7/dist-packages/watson_developer_cloud/watson_service.py”, 第 385 行,根据要求 信息 = error_info,httpResponse = 响应)watson_developer_cloud.watson_service.WatsonApiException:错误: 无效请求:内容为空,代码:400,X-dp-watson-tran-id: gateway02-582988317 , X-global-transaction-id: ffea405d5adda40d22bfb21d

我的代码示例是:

while 1:
    where = file.tell()
    line = file.readline()
    if not line:
        time.sleep(1)
        file.seek(where)
    else:
        if (line):
            print "-----------------------------"
            print "the line is: "
            print line
            print "-----------------------------"
            response = natural_language_understanding.analyze(
                text=line,
                features=Features(
                    entities=EntitiesOptions(
                        emotion=True,
                        sentiment=True,
                        limit=2),
                    keywords=KeywordsOptions(
                        emotion=True,
                        sentiment=True,
                        limit=2)),
                language='en'
                )
            print(json.dumps(response, indent=2))

就是这样Error: invalid request: content is empty no content或无效字符。 你建议有类似的字符\n使用过并且您只检查了空的。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何解决 NLU Watson API 中的内容为空错误? 的相关文章

随机推荐