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 1 person 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

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
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published Apr 09, 2019 in Portfolio for Jira

Portfolio for Jira 3.0 is here!

The wait is over... Portfolio for Jira Server and Data Center 3.0 is now officially here! Platform releases offer Atlassian an opportunity to shift our strategy, make bold predictions about t...

1,353 views 14 25
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