繁体   English   中英

无法通过Web-API将文件上传到Slack

[英]Not able to upload a file to slack via web-api

我正在尝试使用https://api.slack.com/methods/files.upload中提供的Web-API将文件片段上传到Slack中的频道

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

    print "This is a test"
    requests.post('https://slack.com/api/files.upload', data=payload_channel_caller)

但是上面的代码无法上传文件,实际上它可以正确运行。

不知道这是怎么了。

有人可以帮我吗

修改要点:

在脚本中,未读取要上传的文件。 运行脚本时,将检索以下响应。

{"ok":false,"error":"no_file_data"}

此时,来自Slack的状态代码为200。因此不会发生错误。 以上几点反映的脚本如下。

修改后的脚本:

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 = requests.post(
        "https://slack.com/api/files.upload",
        params=param,
        files={'file': f}
    )
    print r.text

如果我误解了您的问题,对不起。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM