【发布时间】:2021-09-25 14:02:27
【问题描述】:
我有一个名为 main.py 的 python 文件,我正在尝试使用特定令牌建立 Prometheus 连接。但是,如果令牌已过期,而不是打印出 prometheus_api_client.exceptions.PrometheusApiClientException 的错误消息,我怎样才能使用 try 和 except 块打印我们喜欢的 status_code: 500, reason: Invalid token 的错误消息。
代码:
#token="V0aksn-as9ckcnblqc6bi3ans9cj1nsk" #example, expired token
token ="c0ams7bnskd9dk1ndk7aKNYTVOVRBajs" #example, valid token
pc = PrometheusConnect(url = url, headers={"Authorization": "bearer {}".format(token)}, disable_ssl=True)
try:
#Not entirely sure what to put here and the except block
except:
我已经在 try 和 except 块中测试了几个代码,但无法摆脱来自 Prometheus 的长错误。有什么建议吗?
【问题讨论】:
标签: python prometheus