The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

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

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
Prince Nyeche - ELFAPP
Atlassian Partner
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