python strftime格式变量



我正在使用这个prometheus json导出器https://github.com/catawiki/json_exporter和我不知道如何使用strftime参数。要求使用中的格式https://docs.python.org/3/library/time.html#time.strftime.据我所知,应该定义一个字符串。如果我设置:

strftime: '%Y-%m-%d'

并将变量用作

params:
start_date: $strftime

我有这个错误

Traceback (most recent call last):
File "/usr/local/lib/python2.7/threading.py", line 801, in __bootstrap_inner
self.run()
File "/usr/local/lib/python2.7/threading.py", line 754, in run
self.__target(*self.__args, **self.__kwargs)
File "/usr/local/lib/python2.7/site-packages/json_exporter/main.py", line 257, in run
self.scrape()
File "/usr/local/lib/python2.7/site-packages/json_exporter/main.py", line 279, in scrape
data = render(self.body, variables)
File "/usr/local/lib/python2.7/site-packages/json_exporter/main.py", line 125, in render
return Template(tmpl).safe_substitute(variables)
File "/usr/local/lib/python2.7/string.py", line 207, in safe_substitute
return self.pattern.sub(convert, self.template)
TypeError: expected string or buffer

正确的使用方法是什么?

谢谢。

所有内容似乎都与文档匹配,即使文档并不清楚要使用datetime.strftimetime.strftime字段(但有趣的是,两者都知道%Y,事件是后者(。

一些尝试:

  • 删除格式模板周围的引号
  • 直接在params中指定模板,而不是使用链接

此外,根据错误stacktrace,您正在运行Python 2.7,这意味着:

  • 您需要的文档就在这个页面上。但不确定会有什么不同
  • 您的有效支持期已过2年,应该认真考虑更新您的系统

最新更新