Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

What server to use to connect python with jira api

Amir Darbar
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 10, 2018

This is my code:

from jira import JIRA

options = {'server': 'https://myaccount.atlassian.net'}
jira = JIRA(options, basic_auth=('username', 'password'))

and it says 

Got recoverable error from GET https://myaccount.atlassian.net/rest/api/2/serverInfo, will retry [1/3] in 3.51334302252s. Err: 401 Unauthorized

5 answers

0 votes
Kais Tounsi June 23, 2019

If somebody still need a solution, you can install JIRA rest api : lib https://pypi.python.org/pypi/jira/. Just a simple example:

https://thepythoncoding.blogspot.com/2019/06/what-server-to-use-to-connect-python.html

from jira.client import JIRA

jira_server = "http://yourjiraserver.com"
jira_user = "login"
jira_password = "pass"

jira_server = {'server': jira_server}
jira = JIRA(options=jira_server, basic_auth=(jira_user, jira_password))

group = jira.group_members("jira-users")
for users in group:
print users
0 votes
Kais Tounsi June 23, 2019

Step by Step how to access the hosted Jira API via python

Using the JIRA python module this example works:

https://thepythoncoding.blogspot.com/2018/07/python-step-by-step-how-to-access.html

from jira import JIRA
jira = jira = JIRA(basic_auth=(un, pwd), options={'server': server})
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]'
0 votes
Ruchit May 31, 2019

@Edwin Kyalangalilwa  I have tried the above process which you mentioned. And I kept 'verify': False so

I am not using SSL CERTIFICATE. 

Edwin Kyalangalilwa
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 4, 2019

@Ruchit 

Are you still getting a 401 error?

Ruchit June 5, 2019

@Edwin Kyalangalilwa 

Yes, I am getting 401 error. Can you please confirm that for testing purpose if 'verify': False i.e.

options = {'server': 'url', 'verify': False}

then SSL Certificate is not required?
0 votes
Ruchit May 31, 2019

Hi @Edwin Kyalangalilwa 

I am trying to connect to "https://jira.mycompany.com" URL using python jira module.

For this do I need to use app token or I can use basic_auth.

Edwin Kyalangalilwa
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 31, 2019

@Ruchit basic_auth

Please check your credentials.

Another thing to try is

options = {'server': 'url', 'verify': False}

 There may be an issue with your SSL certificate.

Piyush Gupta
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 14, 2021

hi @edwin 

 

I am trying to connect to jira using the same method ad it is saying that basic authentication with password is depreciated. 

I am tired searching for it but didn't get how to connect my code with jira.

This is what I a using

options = {'server''https://myaccount.atlassian.net'}   

 jira = JIRA(options, basic_auth=('username','my_password'))

0 votes
Edwin Kyalangalilwa
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 11, 2018

Hi @Amir Darbar,

401 error is related to authentication - possibly the wrong credentials.

I have ran across this when I have special characters in my password and it doesn't get parsed well in the script.

Try

from jira import JIRA
import getpass

password = getpass.getpass()

options = {'server': 'url'}
jira = JIRA(options, basic_auth=('username', password))
Amir Darbar
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 11, 2018

Hi, now I have a different error telling me:

WARNING:root:Got recoverable error from GET http://localhost:2990/jira/rest/api/2/serverInfo, will retry [1/3] in 9.84980195432s. Err: HTTPConnectionPool(host='localhost', port=2990): Max retries exceeded with url: /jira/rest/api/2/serverInfo (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x107467c90>: Failed to establish a new connection: [Errno 61] Connection refused',))

I think its a problem with the url I'm using in options, do you know which URL I have to use to connect to the data of my organization?

Edwin Kyalangalilwa
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 11, 2018

It should be the URL you're using to access JIRA. Also make sure it is the same URL set in your Base URL configuration.

Ruchit May 30, 2019

@Edwin Kyalangalilwa  Even though using the base URL of my company I am getting 401 error and I don't have special char in my password also.

Can you please help me with this.

Edwin Kyalangalilwa
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 31, 2019

Hi @Ruchit

Passwords are deprecated for cloud applications. Please use app tokens.

Client must be authenticated to access this resource.

Suggest an answer

Log in or Sign up to answer