首页 > 解决方案 > 将文件上传到 Slack 在聊天中没有响应

问题描述

我正在尝试txt data使用此代码发送一些

    my_file = {'file' : ('/home/suomi/_data.txt', open('/home/suomi/_data.txt', 'r'), 'txt')}

    payload={
        "filename":"aaaa.txt", 
        "token":API_BOT, 
        "channel":'*my_user_id*',
        }

    x = requests.post("https://slack.com/api/files.upload", params=payload, files=my_file)

    print(x)
    print(x.json())

得到这个回应


<Response [200]>
{'ok': True, 'file': {'id': '*private_id*', 'created': 1603941396, 'timestamp': 1603941396, 'name': 'aaaa.txt', 'title': 'aaaa', 'mimetype': 'text/plain', 'filetype': 'text', 'pretty_type': 'pretty text', 'user': '*my private user_id*', 'editable': True, 'size': 18145, 'mode': 'snippet', 'is_external': False, 'external_type': '', 'is_public': False, 'public_url_shared': False, 'display_as_bot': False, 'username': '', 'url_private': '*private url_link*', 'url_private_download': '*private url_link*', 'permalink': '*private url_link*', 'permalink_public': '*private url_link*', 'edit_link': '*private url_link*', 'preview': "*somedata*", 'preview_highlight': '<div class="CodeMirror cm-s-default CodeMirrorServer" oncopy="if(event.clipboardData){event.clipboardData.setData(\'text/plain\',window.getSelection().toString().replace(/\\u200b/g,\'\'));event.preventDefault();event.stopPropagation();}">\n<div class="CodeMirror-code">\n<div><pre>*somedata*</pre></div>\n<div><pre></pre></div>\n<div><pre>*************************************</pre></div>\n<div><pre></pre></div>\n</div>\n</div>\n', 'lines': 131, 'lines_more': 126, 'preview_is_truncated': True, 'comments_count': 0, 'is_starred': False, 'shares': {}, 'channels': [], 'groups': [], 'ims': [], 'has_rich_preview': False}}

里面的值**由于隐私而被替换。

但我的应用没有收到回复 - 我启用了正确的权限,我可以发送正常的短信。

files:write, channels:history, channels:read, chat:write, groups:history

顺便提一句。我正在尝试向用户发送文件,而不是频道

标签: pythonpython-requestsslack

解决方案


推荐阅读