我正在文件tweet.txt
中发送推文并使用其他python脚本,我正在阅读推文并将其发送给Watson。有时,会产生错误:
回溯(最近一次呼叫最后一次):文件" readingTweets.py",第44行, 在 语言='连接'文件" /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)File " /usr/local/lib/python2.7/dist-packages/watson_developer_cloud/watson_service.py" ;, 第385行,请求中 info = error_info,httpResponse = response)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))
答案 0 :(得分:2)
它是Error: invalid request: content is empty no content
或无效字符。
你建议使用像\n
这样的字符,你只检查空字符。