Home » excel » python – Why are excel files uploaded as zip file?

python – Why are excel files uploaded as zip file?

Posted by: admin May 14, 2020 Leave a comment

Questions:

I have an excel sheet called last_run.xlsx, and I use a small python code to upload it on slack, as follow:

import os
import slack

token= XXX
client = slack.WebClient(token=slack_token)

response = client.files_upload(
        channels="@viktor",
        file="last_run.xlsx")

But when I receive it on slack it is a weird zip file and not an excel file anymore… any idea what I do wrong?

How to&Answers:

Excel files are actually zipped collection of XML documents. So it appears that the automatic file detection of Slack is recognizing it as ZIP file for that reason.

Also manually specified xlsx as filetype does not change that behavior.

What works is if you also specify a filename. Then it will be correctly recognized and uploaded as Excel file.

Code:

import os
import slack

client = slack.WebClient(token="MY_TOKEN")

response = client.files_upload(
        channels="@viktor",
        file="last_run.xlsx",
        filename="last_run.xlsx")

This looks like a bug in the automatic to me, so I would suggest to submit a bug report to Slack about this behavior.