Forums

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

Error 401 when connect Jira using Python jira

Татьяна Бусел
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 10, 2024

Hello! I'm using the JIRA library to collect information about all tickets.

Here is my authorization:

jira = JIRA(options= {'server': 'https://xxx.xx'}, token_auth = 'yyy')

 And here is my code.

issues = []
for i in range(0, total, 1):
try:
tikets = jira.search_issues(JQL, maxResults=1, startAt=i)
for keyid in range(len(tikets)):
key_name = str(tikets[keyid])
issue = jira.issue(key_name, expand='issuelinks,issuetype')
x = {}
x['ID'] = key_name
x['issue_created'] = issue.fields.created
x['project'] = issue.fields.project.name
issues.append(x)
except Exception as e:
print(key_name)
print(f"Ошибка: {e}")
continue

 The code works well on almost all tickets. However, several receive an error 401 - unauthorized. At the same time, I can view these tickets in Jira and receive information through Postman. What could be the problem?

1 answer

0 votes
Prince Nyeche
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 11, 2024

I believe this is one of those rare instances where a session might have been lost during transit when querying Jira issue via the API. I'm not sure what the cause is, but if, you receive this for a small fraction of the tickets. Probably what you can do is auth again within that loop using the same variable name you used to instantiate the auth login, probably that might help.

For example

# initial jira auth here
# ...
for i in some_loop:
# do some loops here
...
jira = JIRA(options= {'server': 'https://xxx.xx'}, token_auth = 'yyy')
# other code about other stuff here

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, jira cloud certification, managing jira projects, jira project administration, jira cloud exam, atlassian certification, agile project management, jira workflows, jira permissions, jira training, jira cloud skills, atlassian learning

Become a Certified Jira Service Project Expert 🦸🏻‍♂️

Validate your expertise in managing Jira Service Projects for Cloud. Master configuration, optimize workflows, and manage users seamlessly. Earn global 🗺️ recognition and advance your career as a trusted Jira Service management expert.

Get Certified! ✍️
AUG Leaders

Atlassian Community Events