我使用jira python包连接到JIRA:
def connect_to_JIRA():
'''
Generic function to get JIRA connection
'''
if settings.JIRA_AVAILABLE:
try:
jira_conn = JIRA(
basic_auth=(settings.JIRA_USER, settings.JIRA_PASSWORD),
server=settings.JIRA_SERVER
)
return jira_conn
except Exception as e:
log.error("Unexpected problem connecting to JIRA")
raise
else:
log.error("JIRA credentials not configured or incomplete")
raise
哪种方法可以正常使用,但如果凭据不正确(不缺失)则会经过1-2分钟的歌曲和舞蹈:
WARNING:root:Got recoverable error from GET [my jira server address], will retry [1/3] in 1.7998166159998785s. Err: 401 Unauthorized
WARNING:root:Got recoverable error from GET [my jira server address], will retry [2/3] in 39.04052373359595s. Err: 401 Unauthorized
WARNING:root:Got recoverable error from GET [my jira server address], will retry [3/3] in 46.35106211454652s. Err: 401 Unauthorized
在最终触发我的except子句之前。有没有办法让它“快速失败”?
答案 0 :(得分:2)
将max_retries
设置为1.当前默认值为3
。
jira_conn = JIRA(
basic_auth=(settings.JIRA_USER, settings.JIRA_PASSWORD),
server=settings.JIRA_SERVER,
max_retries=1
)