0

I have a mystery as to why one type of excel file will decode but the other will not. Here is what the two different files come in as:

The only difference that I can see is that one comes in with _content data.

Here's the code I run to try and make a local excel file based on this information:

 for msg in email_from_radar:
    for attachment in msg.attachments:
        fpath = os.path.abspath(table_id + '.xlsx')
        with open(fpath, 'wb') as f:
            f.write(attachment.content)

        break
    break

essentially I'm just naming a path for the file then trying to write the excel file to that path. The only thing I can think of is that the file that doesn't work is much smaller.

Dan Mašek
  • 17,852
  • 6
  • 57
  • 85
  • A `FileAttachment` will only have something in its `_content` attribute after you access its `.content` property. So make sure to access that before printing the object. Regarding the file that Excel apparently has problems opening; are you sure it's not simply a broken file? Can you open the file via e.g. Outlook? – Erik Cederstrand Aug 19 '20 at 11:50
  • @ErikCederstrand Hi Erik thanks for the help. broken file seems like it was the issue. I've been running the same process now with similar files that are coming in daily and it is working well. – Andrew Marotta Aug 25 '20 at 13:40

0 Answers0