atlassian-python-api icon indicating copy to clipboard operation
atlassian-python-api copied to clipboard

Error in download_attachments_from_page() with some file names

Open jsancs opened this issue 1 year ago • 3 comments

Hi!

Using the method download_attachments_from_page() raises an exception when the filename is not sanitize Eg: image2019-9-13 11:51:31.png this file raises an error, I believe that is caused by the colons (:)

jsancs avatar Mar 20 '24 12:03 jsancs

which instance do you use? DC or cloud (if DC which version). Is it jira or confluence? Also if possible, provide complete error trace.

gkowalc avatar Mar 20 '24 13:03 gkowalc

I think that it is not related to the client. Looking into the code I found this in atlassian/confluence.py:

for attachment in attachments:
  file_name = attachment["title"]
  if not file_name:
      file_name = attachment["id"]  # if the attachment has no title, use attachment_id as a filename

Line 1338, in the download_attachments_from_page() definition. In the code the file name is used exactly as it is defined in Confluence, but some special characters (like colons) can cause an error in the filesystem. I have used a regexp in my local package to sanitize the file name and it seem to solve the problem

jsancs avatar Mar 20 '24 13:03 jsancs

On macOS host, it seems to be fine. Are you using a Windows host? According to https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file, a colon shouldn't be used for files or directory names. Therefore, I don't think the problem is with the library code. I can add a small comment to the code with a warning.

gkowalc avatar Mar 22 '24 19:03 gkowalc

Let's close it, as it's mostly need to be wrapped external code for now

gonchik avatar Apr 01 '25 21:04 gonchik