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 do I access the hosted Jira API via python?

Using the JIRA python module this example works:

 

from jira import JIRA
jira = JIRA('https://jira.atlassian.com')
issue = jira.issue('JRA-9')
print(issue.fields.project.key) # 'JRA'
print(issue.fields.issuetype.name) # 'New Feature'
print(issue.fields.reporter.displayName) # 'Mike Cannon-Brookes [Atlassian]'

But I can get authentication working.

For example how do I query an issue named ISE-4 in a project name MYPROJECT

I tried authed_jira = JIRA(basic_auth=('myuser', 'mypass')) but this does not seem to work.

Does the hosted JIRA API support basic authentication?

3 answers

1 accepted

3 votes
Answer accepted

you should use the following format:

jira = JIRA(basic_auth=(un, pwd), options={'server': server})

you need to pass in the server details as a connection option when you are specifying basic_auth.

in the example above, un pwd and server are all string variables.

When I try that I get a syntax error:

 

from jira import JIRA
 
#jira = JIRA('https://jira.atlassian.com')
jira = JIRA(basic_auth=('user', 'password123!'), options={'https://myaccount.atlassian.net'})
issue = jira.issue('blah-12')
print(issue.fields.project.key) 
print(issue.fields.issuetype.name) 
print(issue.fields.reporter.displayName)

 

I Get this error:
ValueError: dictionary update sequence element #0 has length 29; 2 is required

You haven't setup your dictionary correctly in the example above, you just specified the url as a key with no value, instead of a key/value pair.

Options should be:

options = {'server': 'https://myaccount.atlassian.net'}
Like Ricardo Cerceau likes this

Ah sorry new to python, looks like she workin now thanks a bunch.

This works ....

from jira import JIRA

def main():

   options = {'server': jiraURL}
   jira = JIRA(options, basic_auth=(jiraUserName, jiraPassword))
   issue = jira.issue('ESS-138581')

   print issue.fields.project.key
   print issue.fields.issuetype.name
   print issue.fields.reporter.displayName
   print issue.fields.summary
   print issue.fields.project.id

if __name__== "__main__" :
     main()

 

If you get handshake error [SSLV3_ALERT_HANDSHAKE_FAILURE]. Kindly install the following modules in python

  • pyOpenSSL
  • ndg-httpsclient
  • pyasn1

Great !! this sample of code works..

While trying above code @Harihar Pai I am getting below error:

WARNING:root:Got recoverable error from GET https://jira.company name/rest/api/2/serverInfo, will retry [1/3] in 6.687988879187072s. Err: 401

Can anyone explain to me why I am getting this error

Same here, on-premise jira is giving this error out of nowhere 

@Ruchit @Aibek Prenov When I was using this module with on prem JIRA, I could not use my real username to authenticate, but I had to use the JIRA assigned user key. In my organization, the key is of the form 'cc######'. I am not sure where you can determine your user key. For me, if I attempt to login to the web UI with my regular username, but the wrong password, when I am redirected back to the login page, my real username has been replaced with my user key.

Python | Step by Step how to access the hosted Jira API via python
[http://thepythoncoding.blogspot.com/2018/07/python-step-by-step-how-to-access.html]

you should use the following format:

jira = JIRA(basic_auth=(un, pwd), options={'server': server})
Like Ricardo Cerceau likes this
from jira import JIRA
jira = jira = JIRA(basic_auth=(un, pwd), options={'server': server})
Like Ricardo Cerceau likes this

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira

Calling all Jira Cloud users! Give us feedback on our exploration of a new navigation.

Hi everyone! My name’s Matt and I’m a product manager at Atlassian. I work in the navigation & findability space for all our Jira Cloud products. We’ve been working on trying to improve the exp...

1,236 views 20 12
Join discussion

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