1

I am trying to use the Jira python library to do some quite basic things. Even before doing anything, the constructor fails.

address = 'https://myaddress.atlassian.net'
options = {'server': address}
un = '[email protected]'
#un = 'my' #also doesn't work
pw = 'the_pasSword!'
cookie = (un, pw)

j = JIRA(options, basic_auth=cookie)

This is ALL the code.

The last line fails with

WARNING:root:Got recoverable error from GET https://myaddress.atlassian.net/rest/api/2/serverInfo, will retry [1/3] in 13.906688704524315s. Err: 401

WARNING:root:Got recoverable error from GET https://myaddress.atlassian.net/rest/api/2/serverInfo, will retry [2/3] in 4.071181495745648s. Err: 401

WARNING:root:Got recoverable error from GET https://myaddress.atlassian.net/rest/api/2/serverInfo, will retry [3/3] in 6.266303262421157s. Err: 401

Trying the credentials manually on atlassian do work, and I am able to log in.

Any idea why this very straightforward attempt to connect wouldn't work?

1
  • Is this the library you're using? jira.readthedocs.io/en/master It looks like there are a few ways to authenticate to JIRA and it will depend on how your JIRA server is set up. Commented Apr 18, 2019 at 17:06

2 Answers 2

3

They have been discussing deprecating passwords in basic auth. Try generating an API token and using that in replacement of your password.

https://developer.atlassian.com/cloud/jira/platform/deprecation-notice-basic-auth-and-cookie-based-auth/

address = 'https://myaddress.atlassian.net'
options = {'server': address}
un = '[email protected]'
#un = 'my' #also doesn't work
token = 'the_tokEn'
cookie = (un, token)

j = JIRA(options, basic_auth=cookie)
Sign up to request clarification or add additional context in comments.

4 Comments

This worked! However... according to developer.atlassian.com/cloud/jira/platform/… username usage will not be supported starting very soon. What more should I do?
Looks like you should just go ahead and test using the accountID as you linked to. Does it work when you use that?
The docs are extremely unclear on what gets deprecated. Contacted official support, and they said mail+token will continue working, so that's that, thanks!
From 2020-01-03 it does not work anymore with JIRA client ver 2.0.0, but still works with curl call: curl -v company.atlassian.net --user email:token
0

Please try this code:

from jira.client import JIRA
import logging
import getpass
import datetime
import os

# Clearing the screen
os.system('cls||clear')
# Getting user authentication data
print 'Please enter your authentication data'
USER = raw_input('Username: ')
PASSWORD = getpass.getpass('Password: ')
print
JIRA_URL = "YOUR_JIRA_URL"
i = datetime.datetime.now()
TODAY = ("%s/%s/%s" % (i.day, i.month, i.year) )

def connect_jira(log, jira_server, jira_user, jira_password):
    '''
    Connects to JIRA

    Returns None on error
    '''
    try:
        log.info("Connecting to JIRA: %s" % jira_server)
        jira_options = {'server': jira_server}
        jira = JIRA(options=jira_options, basic_auth=(jira_user, jira_password))
                                        # ^--- Note the tuple
        return jira
    except Exception,e:
        log.error("Failed to connect to JIRA: %s" % e)
        return e

# Creating logger
log = logging.getLogger(__name__)
# Creating a Jira connection object, jc
jc = connect_jira(log, JIRA_URL, USER, PASSWORD)

2 Comments

error 401. Why is this different? The log outputs the html code for a page that says "error 401" more or less
@Gulzar This works 100% on my install but, as you correctly found out in the other answer, in the new Jira version only tokens are accepted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.