为了账号安全,请及时绑定邮箱和手机立即绑定

当提供的密码不正确时,如何停止对Jira的递归登录尝试?

当提供的密码不正确时,如何停止对Jira的递归登录尝试?

喵喔喔 2022-08-11 17:47:26
我正在使用python构建一个实用程序来连接到Jira并提取TEST覆盖率。作为此工具的一部分,我要求用户输入用户凭据。该工具会等待用户输入,例如输入usid / pwd,一旦成功,则要求提供Jira查询。然后,它运行查询并提供结果。这里的问题是,作为一个负面场景,我尝试输入了一个不正确的密码,但后来Jira本身尝试了多次使用不正确的凭据并锁定了帐户。我们如何在第一个警告本身中停止这种重试,并捕获该警告以提醒用户检查其输入的密码/usid是否正确?我尝试了尝试/except block,但它似乎没有抓住它。警告:root:从GET https://jira.xxxxxxcom/rest/api/2/serverInfo 获取错误,将在1.5083078521975724中重试[1/3]。错误: 401警告:root:从 GET https://jira.xxxxxxcom/rest/api/2/serverInfo 获取了可恢复的错误,将在 35.84973140451337 中重试 [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 ")
查看完整描述

2 回答

?
蝴蝶刀刀

TA贡献1801条经验 获得超8个赞

有点晚了,但对于其他任何寻找答案的人来说,JIRA对象的构造函数上有一个max_retries属性。

            self.__jira = JIRA(
                basic_auth=(username, password),
                max_retries=0,
                options={
                                    'server': 'https://jira.dummy.com/'
                }
            )

您可以在源代码中看到该变量和其他变量 https://jira.readthedocs.io/en/master/_modules/jira/client.html?highlight=max_retries#


查看完整回答
反对 回复 2022-08-11
?
慕沐林林

TA贡献2016条经验 获得超9个赞

您似乎希望 在失败时提示用户输入有效的凭据。您不是每次尝试身份验证时都请求凭据,因此请将输入语句移动到无限循环中并尝试以下操作:


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 语句后中断是没有意义的。


查看完整回答
反对 回复 2022-08-11
  • 2 回答
  • 0 关注
  • 204 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号