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#

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 語句后中斷是沒有意義的。
添加回答
舉報