我正在使用 CheckMK 2.2.0 及其 Nginx 插件来监控某些主机。该代理正在使用无法更新的 Python 3.4.2 的主机上运行。在此主机上运行 Nginx 插件时,我收到语法错误:
# python3 nginx_status.py
File "nginx_status.py", line 126
config: dict = {}
^
SyntaxError: invalid syntax
代码如下:
def main(): # pylint: disable=too-many-branches
config_dir = os.getenv("MK_CONFDIR", "/etc/check_mk")
config_file = config_dir + "/nginx_status.cfg"
config: dict = {}
if os.path.exists(config_file):
with open(config_file) as open_config_file:
config_src = open_config_file.read()
exec(config_src, globals(), config)
使用 Python 3.11.2 在另一台主机上运行此脚本可以正常工作。但正如我所说,我无法更新较旧的 Python 版本。我是一名 PHP 程序员,但不懂 Python。
这种类型的代码是什么
config: dict = {}
以及如何修复它以在 Python 3.4 上运行?
Python 3.4 太旧,无法支持类型注释。您真的应该将其升级到安全且受支持的版本。 3.4 已于 2019 年 3 月 18 日结束。