Unable to connect to JIRA from python

Tushar Mishra June 9, 2018

This code works and prints out the list of projects accessible to anonymous user

---------------------This Works-----------

from collections import Counter
from jira import JIRA
import re

options = {
'server': 'https://jira.atlassian.com'}

jira = JIRA(options)

projects = jira.projects()
for v in projects:
print (v)

-------------------------THIS DOES NOT WORK-------

from collections import Counter
from jira import JIRA
import re


options = {
'server': 'https://jira.atlassian.com'}

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

projects = jira.projects()
for v in projects:
print (v)

-------------------------------------ERROR-------------------

 WARNING:root:Got recoverable error from GET https://jira.atlassian.com/rest/api/2/serverInfo, will retry [1/3] in 17.384401903628806s. Err: 401
WARNING:root:Got recoverable error from GET https://jira.atlassian.com/rest/api/2/serverInfo, will retry [2/3] in 36.83359655277892s. Err: 401
WARNING:root:Got recoverable error from GET https://jira.atlassian.com/rest/api/2/serverInfo, will retry [3/3] in 58.065338652808876s. Err: 401 

-------------------------------------------------------

Please help with answer

 

3 answers

1 accepted

2 votes
Answer accepted
Alexey Matveev
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 9, 2018

Hello,

It means that you are not authenticated in Jira. Are you sure that you provide valid credentials for basic_auth? Does your Jira instance use basic authentication?

Tushar Mishra June 9, 2018

Credentials are valid, since I could open the same JIRA link and provide my credentials and login. I use it daily via web.

How do I know if my JIRA instance uses basic authentication or not?

Thanks for your reply.

Tushar Mishra June 9, 2018

You are awesome Alexey!!! Got it working. There was an issue with the url which I gave, I had to remove "login.jsp" and it worked.

Thanks a lot!!!

Alexey Matveev
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 9, 2018

You are welcome!

Palash Pandey September 28, 2018

Hey! I think I have the same issue, can you share how I can see if my JIRA instance uses basic authentication or not? 

Thank you in advance! 

3 votes
ayarosh May 26, 2019

I think that the problem is in official Python library.

It works:

curl --user MY_JIRA_USER:MY_JIRA_PASSWORD -X GET
-H "Content-Type: application/json"
https://MY_JIRA_DOMAIN.atlassian.net/rest/api/latest/issue/MY_ISSUE_NUMBER

It's NOT works:

from jira import JIRA

server = 'https://MY_JIRA_DOMAIN.atlassian.net'
user = 'MY_JIRA_USER'
pass = 'MY_JIRA_PASSWORD'

options = {'server': server}
jira = JIRA(options=options, basic_auth=(user, pass))

print(jira.issue(MY_ISSUE_NUMBER))

I've got the correct response using terminal but not from Python.

It proves that my credentials and user permissions in Jira is fine.

Amir Harel June 25, 2019

I have same problem.

Renz Roque June 26, 2019

same problem.  please help

JC May 12, 2022

Spent 2 hours on this, and it turns out that python code (whether `JIRA` or `requests`) will use my system proxy automatically while `curl` won't, and appearently the server rejects requests from my proxy...

Suggest an answer

Log in or Sign up to answer