Kittystone Kittystone - 1 year ago 167
Python Question

Not able to upload a file to slack via web-api

I am trying to upload a file snippet to a channel in slack using Web-API available at

payload_channel_caller = {'token': 'xoxpxxxxb1d8529c', 'channel':'C1PJ17FFT', 'file': "/home/nsingh/slack_shift/user_list" ,'title':'Shifters'}

print "This is a test"'', data=payload_channel_caller)

But the above code is not able to upload the file, infact it runs right through with no error .

Not sure whats wrong here.

Can someone help me out

Answer Source

Modification points :

In your script, the file you want to upload is not read. When your script is run, following response is retrieved.


At this time, the status code from Slack is 200. So no error occurs. The script which was reflected above points is as follows.

Modified script :

import requests
uploadfile = "/home/nsingh/slack_shift/user_list"  # Please input the filename with path that you want to upload.
with open(uploadfile, 'rb') as f:
    param = {
        'token': 'xoxpxxxxb1d8529c',
        'channels': 'C1PJ17FFT',
        'title': 'Shifters'
    r =
        files={'file': f}
    print r.text

If I misunderstand your question, I'm sorry.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download