In http://pythonhosted.org/jira/ it states you can get the attachment resource via the call: JIRA.attachment
(id)
However, once you get the resource, is there a way to actually download the attachment?
I used a method as such
from jira import JIRA
jira = JIRA(auth=('<username>','<password>'), options={'server': <URL>})
jira_issue = jira.issue(<issue>, expand="attachment")
for attachment in jira_issue.fields.attachment :
image = attachment.get()
jira_filename = attachment.filename
with open(jira_filename, 'wb') as f:
f.write(image)
Other authentication methods also exist, for example I used OAuth. More info on that can be found here.
It's worth noting that I couldn't download files with a space in the attachment's file name using the jira module and had to update my code to use the attachment's .inter_content() attribute and iterate through the content.
#Write the file to the issue_path directory
with open(jira_filename, 'wb') as f:
#if there is a space in the filename (attachment.get() crashes in this case)
if " " in jira_filename:
for chunk in attachment.iter_content(chunk_size=512):
if chunk: # filter out keep-alive new chunk
f.write(chunk)
else:
#Getting the file from the jira server and writing it to the current directory
image = attachment.get()
f.write(image)
You can do it with request like this:
response = requests.get('filepath', auth=('user', 'pass'), stream=True) with open("attachments/"+filename, 'wb') as out_file: shutil.copyfileobj(response.raw, out_file) del response
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The object returnet by jira.attachment(id) method has itself a method called get, did you try it?
Another way is to user the property content to get the JIRA url to the attachment and get it through a http request.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have tried the same thing, the http route just returns a garbage 30 kb csv file and I couldn't find a GET method for JIRA?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.