The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to catch in python failed login to jira ?

Przemyslaw Bak
Contributor
December 21, 2015

Hi all,

 

currently I am using the following code to login to JIRA using python:

...
jira = JIRA(options=jira_options, basic_auth=(user,pass))
...

Let's say the user provided wrong username or password. How do I know what is the reason of failed login ?

How do I catch that ?

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

3 votes
Answer accepted
Joe Clark
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 4, 2016

Ah, actually it looks like you are using the jira-python library? In this case it looks like you can rely on the HTTP Status code and look for a code of 401 to indicate a login failure.  Here's an example:

from jira import JIRA
from jira.exceptions import JIRAError

options = {
    'server': 'http://localhost:2990/jira'
}

try:
    jira = JIRA(options=options, basic_auth=('fred', 'blargh'))
except JIRAError as e:
    if e.status_code == 401:
        print "Login to JIRA failed. Check your username and password"

print "done!"
Przemyslaw Bak
Contributor
January 4, 2016

Thanks a lot @Joe Clark [Atlassian] smile

That is what I needed !

Like Pawan Kumar likes this
Joe Clark
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 5, 2016

No problem :)

holding telnet
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 21, 2018

thaks

Pawan Kumar
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 28, 2020

Thanks a lot @Joe Clark

0 votes
Joe Clark
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 21, 2015

The HTTP response from JIRA will contain a HTTP header called X-Seraph-LoginReason.  If the header has a value of OK, then the login was successful.  If the header is absent, or contains any other value, then the login failed.

Note that if the JIRA instance is using a custom authenticator (such as if some kind of SSO integration is enabled), then different rules will be in effect at the full discretion of the specific authenticator.

 

 

Przemyslaw Bak
Contributor
January 4, 2016

Hi @Joe Clark [Atlassian],

can you please include some simple example showing how to deal with it ?

Like Pawan Kumar likes this
TAGS
AUG Leaders

Atlassian Community Events