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
Accepted answer

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'}

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
0 votes
IPTV KODI I'm New Here Jul 04, 2018

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]

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Monday in Jira Software

Implementing Jira in Small Business

Introduction This article will give insight on how a small software development department implemented Atlassian products to enhance and streamline the business process. The privately held company h...

300 views 2 8
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you