Forums

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

Need help with Atlassian Jira Python library on Data Centre

Stephen Ellwood
Contributor
February 28, 2025

I have been using the Atlassian Python api library now for a couple of years on our Cloud instance and have managed to make it work quite well.  

We are going to migrate to the Datacentre version so I have just tried the same code on there and it does not work.

I created a token and it seems to authorize me ok but whenever I use any class methods of the jira object it comes back with:

HTTPError: Unauthorized (401)

I can see the project and do the same search from my browser window.  Does anyone else have experience of using this Library on a data centre Jira instance? 

https://atlassian-python-api.readthedocs.io/jira.html#get-issues-from-jql-search-result-with-all-related-fields

2 answers

1 accepted

0 votes
Answer accepted
Stephen Ellwood
Contributor
March 31, 2025

With the help of my IT department I was able to work out how to make it work.  The confusion came because the Jira instantiation call did not throw an error even though the authentication failed.

It turns out that the authentication is quite different between cloud and data center. The cloud uses a username + password (which is actually a token) and the Data Centre uses only a token passed using the keyword token.

I wrote a general function to open the instance based on the login information contained in a file.

def open_jira(wiki_id):
"""Open Jira instance with the credentials given

Args:
----
wiki_id: textfile containing URL and login information for the needed Jira
first line is "url <url of jira instance> <DC|Cloud>"
second line is:
for DC: "token <valid token for instance>"
for Cloud: "pass email.address@company.com:token"
"""
try:
with open(wiki_id, 'r') as f:
url_txt = f.readline().replace("\n", "")
id_txt = f.readline()
except FileNotFoundError:
raise LookupError(f'check {wiki_id} is present')

try:
tag, instance, instance_type = url_txt.split(' ')
assert tag == "url", "keyword url is missing"
assert instance_type in ['DC', 'Cloud'], f'{instance_type}: only DC and Cloud allowed'
except:
raise LookupError(f'check url line in {wiki_id}')

try:
if instance_type == 'DC':
tag, pat = id_txt.split(' ')
assert tag == 'token'
handle = Jira(url=instance, token=pat)
else:
assert ' ' in id_txt and ':' in id_txt, 'password file has wrong format'
name, token = id_txt.split(' ')[-1].strip().split(':')
handle = Jira(url=instance, username=name, password=token)
except:
raise LookupError(f'check credentials in {wiki_id}')

return instance, handle

Hope this helps anyone else having the same issue.

 

0 votes
Mirek
Community Champion
February 28, 2025

Hi @Stephen Ellwood 

Not exactly sure what your scripts are doing but if you are able to login (authorize) and do a simple check on API then you should ok in general.. 

# Simple API call to test
user = jira.myself()
print(user)

Then you have to step by step check what line exactly is failing in the script.. 

Cloud and Data Center APIs are a little bit different so it might be a problem however if you are using some library that should work on both then we have to check if this is not some kind of bug..  

Double-check also with your Jira settings to ensure that the correct permissions is set for your user and project.

If you continue to have problem please share some more information. Everything might be useful to troubleshoot. 

Stephen Ellwood
Contributor
March 2, 2025

HI Mirek,

thanks for the quick reply.  My first code immediately did a jira search but when that failed I looked for the simplest command I could try and came up with user = jira.myself(). I also put a print statement after creation of the jira object and this proved that the open was ok.

I have asked IT to check the correct permissions are set for the project.  Are there separate permissions for me as a HTTPS browser and me as a tokenised browser?

The code I use is:

from atlassian import Jira

jira = Jira(url=instance, username=name, password=token)

print('Jira open', jira)

print(jira.myself())

 

Mirek
Community Champion
March 29, 2025

From what I know if you use your user to authenticate over UI or REST API permissions should be the same / respected (I mean you should be able to get the same data no matter of method you reach Jira data) 

Did IT checked permission on specific project? 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events