It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to catch in python failed login to jira ?

Przemyslaw Bak Dec 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

2 votes
Answer accepted
Joe Clark Atlassian Team Jan 04, 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'

    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 Jan 04, 2016

Thanks a lot @Joe Clark [Atlassian] smile

That is what I needed !

Joe Clark Atlassian Team Jan 05, 2016

No problem :)

holding telnet I'm New Here Dec 21, 2018


0 votes
Joe Clark Atlassian Team Dec 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 Jan 04, 2016

Hi @Joe Clark [Atlassian],

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

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Jira

Try Jira Cloud for Outlook: Organize your work without leaving your inbox

Hi Atlassian community, My name is Max and I work on the product integration team at Atlassian. I am pleased to announce the early access program for the Jira Cloud add-in for Outlook. This add-in...

2,448 views 6 15
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you