0
votes

So, I need to download attachments to the issue in Jira using python. I have next code

from atlassian import Jira

issue = jira.issue(issuekey, fields='summary,comment,attachment')

for attachment in issue['fields']['attachment']:
with open((attachment.filename), 'wb') as file:
    file.write(attachment.get(b'', b''))

After running the code I'm getting 3 empty files(txt, png, png) without any data inside..

How can I get(download) files from issue to my current folder?

2
attachment.get() ? - Rakesh
@Rakesh when I'm using just attachment.get() I'm getting an issue: TypeError: get expected at least 1 arguments, got 0 - Artsom

2 Answers

2
votes

Try using expand="attachment"

Ex:

issue = jira.issue(issuekey,  expand="attachment")

for attachment in issue['fields']['attachment']:
    with open(attachment.filename, 'wb') as file:
        file.write(attachment.get())
1
votes

You need the link to the contents of the attachment which is stored under the key 'content'. Then just use .get() request, that is in Jira library:

for attachment in issue['fields']['attachment']:
    link = attachment['content']
    link = link.split("https://jira.companyname.com/")[1]
    b_str = jira.get(link, not_json_response=True)
    with open((attachment['filename']), 'wb') as file:
        file.write(b_str)

Notice that you need to trim the link, because jira.get() automatically includes the domain to the request url.