我正在使用python构建实用程序以连接到Jira并提取TEST覆盖率。作为此工具的一部分,我要求用户输入用户凭据。该工具等待用户输入,例如输入usid / pwd,一旦成功,然后要求提供Jira查询。然后,它运行查询并提供结果。
这里的问题是,作为一种消极的情况,我尝试输入了错误的密码,但随后Jira本身尝试使用该错误的凭据多次尝试并锁定了帐户。
在第一个警告本身中<<< [我们如何停止此重试并捕获该警告以提醒用户检查其输入的密码/用户名是否正确?我在try / except块中尝试过,但似乎没有抓住它。警告:root:从GET https://jira.xxxxxxcom/rest/api/2/serverInfo获得的可恢复错误,将在1.5083078521975724s中重试1/3。错误:401警告:root:从GET https://jira.xxxxxxcom/rest/api/2/serverInfo获得可恢复的错误,将在35.84973140451337s中重试[2/3]。错误:401
下面的我的代码:
pwd=input("Enter Jira credentials") while True: **try:** jira = JIRA(options={'server': 'https://jira.dummy.com', 'verify': False}, basic_auth=(os.getlogin(), pwd)) //executing this line internally retry the same invalid credential many times return jira // returns jira handle to another function to process. break **except JIRAError as e:** if (e.status_code == 401): print("Login to JIRA failed. Check your username and password") pwd = input("Enter your password again to access Jira OR you may close the tool ")
while True:
pwd=input("Enter Jira credentials")
try:
jira = JIRA(options={'server': 'https://jira.dummy.com', 'verify': False}, basic_auth=(os.getlogin(), pwd)) //executing this line internally retry the same invalid credential many times
return jira // returns jira handle to another function to process.
except JIRAError as e:
if (e.status_code == 401):
print("Login to JIRA failed. Check your username and password")
pwd = input("Enter your password again to access Jira OR you may close the tool ")
这将要求您再输入一次凭据,然后再尝试使用相同的旧内容。在try语句中,在return语句后保持中断是没有意义的。