gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 02:27:31 25 4
gpt4 key购买 nike

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

Traceback (most recent call last): File "readingTweets.py", line 44, in language='en' File "/usr/local/lib/python2.7/dist-packages/watson_developer_cloud/natural_language_understanding_v1.py", line 173, in analyze method='POST', url=url, params=params, json=data, accept_json=True) File "/usr/local/lib/python2.7/dist-packages/watson_developer_cloud/watson_service.py", line 385, in request info=error_info, httpResponse=response) watson_developer_cloud.watson_service.WatsonApiException: Error: invalid request: content is empty, Code: 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))

最佳答案

就是这样错误:无效请求:内容为空无内容或无效字符。您建议使用 \n 之类的字符,而您只检查了空字符。

关于python - 如何解决 NLU Watson API 中的内容为空错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49977879/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com