'Python script to download files from JIRA using API Token

I am new to Python and I am trying to create a script which logs into my JIRA system using the API key, downloads the issue list and and save it under my local drive. I am using the below script . But when I run the script I am getting the below error

url="https://auditservice.dev.azure.com/{org}/_apis/audit/downloadlog?
SyntaxError: EOL while scanning string literal

See the script I used below

import requests

jira_token = 'xxxxxxxx'

url = 'https://yyy.atlassian.net/sr/jira.issueviews:searchrequest-csv-all-fields/temp/SearchRequest.csv?jqlQuery=project+%3D+%22MASTER%22+ORDER+BY+created+DESC&atl_token=2d4dafe6-9c30-4e22-add9-7b3a2cea877b_8c7b7f55de7b75e76ea3f997ed4b30959c1eaf05_lin&tempMax=1000'

r = requests.get(url, auth=('[email protected]', jira_token))

open('MyJiraIssues.csv', 'wb').write(r.content)


Solution 1:[1]

I assume you are using JIRA Cloud. If you are using on-premise Jira, you will need to obtain the security token from Atlassian. There is no such thing as a temporary auth token in Jira, so the Atlassian documentation states that it only works for a limited time and needs to be renewed periodically. For example, if I have an auth token ending at 2020-05-30T13:42:22.123+0000, I need to use it until this date (or later). If it expires earlier than that, I need to get a new one.

If your auth token expires, you can always get a new one by logging in to your Jira account and following the steps in How do I generate an authentication token?. But this creates a new auth token each time so it is not recommended if you are using on-premise Jira. If you are using Cloud, then this is the only option. When you get the new auth token, it can be used just like the one you got in the first place. If your auth token expired, you can use the new one right away.

JIRA has a help page which talks about this in more detail.

If you get the error that says "EOL while scanning string literal", then you are trying to decode a byte string and not a unicode string. You need to change your code from this:

open('MyJiraIssues.csv', 'wb').write(r.content)

to this:

open('MyJiraIssues.csv', 'w').write(r.content)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 PJMan0300