1
votes

In Python, I used to be able to authenticate with JIRA over REST using a simple bit of code:

from jira import JIRA

my_JIRA_username = 'my_name'
my_JIRA_pass = 'my_password'
server = {'server': 'https://my_site.atlassian.net'}
jira = JIRA(server, basic_auth = (my_JIRA_username, my_JIRA_pass))

And then be able to do something simple like:

my_issue = jira.issue('MYISSUE-1')
print my_issue.key

But JIRA has changed things, and I am guessing no longer allows basic authentication like this via the REST API. Instead I get a 401 error.

I tired creating an API token, as suggested here: https://confluence.atlassian.com/cloud/api-tokens-938839638.html except I have NO idea where to use it (it doesn't work if I just use it as a password, like in the code above).

I looked into OAuth as an alternative but I cannot find any code that goes from point A to B that makes ANY sense to me.

Instead I find things like this: https://bitbucket.org/atlassianlabs/atlassian-oauth-examples/src/master/python/app.py

Which is pure gibberish to me. It can't be that complicated!

Can anyone help with a simple jira-python example of using something other than basic authentication that moves from the initialization to a simple REST call?

It would be most appreciated! I have months of work that are now useless merely because I can no longer authenticate.

Also, if you can explain how and when to use the API token that JIRA allows you to generate on their cloud instance, that would be appreciated to, as I don't understand that either!

1
Your script says "my_JIRA_username" -> have you tried using your email address + api token instead? Because Atlassian has removed usernames from the cloud as well.s.hesse
@s.hesse yes, that was the solution. Thanks!landspeedrecord

1 Answers

5
votes

Since using password is already deprecated in basic auth, API tokens are to be used in its place (as you've stumbled upon). In your code you need to use email in place of username and apiToken instead of password. In your code it should be

# jira = JIRA(server, basic_auth = (my_JIRA_username, my_JIRA_pass))
jira = JIRA(server, basic_auth = (email, apiToken))

Try it out and do tell us how it goes.