我编写了一个 python 代码来生成一个 YAML 文件(名为 targets.yml
),该文件由一个名为 prometheus 的流行监控应用程序读取。 prometheus 成功读取了 YAML 文件及其内容,但它也在日志中抛出如下错误。
level=error msg="Error reading file "/var/targets/targets.yml": yaml:
line 218: found unexpected end of stream" source="file.go:199"
我无法摆脱这个错误,尽管我适当地关闭了 YAML 文件,下面是代码:-
while True:
create()
with open('/var/targets/targets.yml', 'w') as output:
print "opened the file to write"
i=0
for item in result:
if(item != None and item['status'] == "ACTIVE"):
print item['domains']['partner']
print item['status']
output.write("\n\n")
output.write("- targets: ['" + "https://" + item["domains"]["agency"] + "']\n")
output.write(" labels:\n")
output.write(" alias: " + item["alias"])
foo=item["name"]
#print foo
if isinstance(foo,basestring):
foo=foo.encode('utf8')
else:
foo=unicode(foo).encode('utf8')
output.close()
print("Waiting for 300 seconds, before relooping")
time.sleep(100)
我也不认为我的文件扩展名有任何区别。有人可以建议吗?
原文由 Suhas Chikkanna 发布,翻译遵循 CC BY-SA 4.0 许可协议
在我的例子中,报价的开盘价和收盘价之间存在不匹配
"
,但错误发生在另一个地方,然后是错误报告的行。