Python-slack-sdk: files_upload silently failing

Created on 24 Jun 2020  路  2Comments  路  Source: slackapi/python-slack-sdk

Description

.files_upload does not upload files whereas the response looks valid

What type of issue is this? (place an x in one of the [ ])

  • [x] bug
  • [ ] enhancement (feature request)
  • [ ] question
  • [ ] documentation related
  • [ ] testing related
  • [ ] discussion

Requirements (place an x in each of the [ ])

  • [x] I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • [x] I've read and agree to the Code of Conduct.
  • [x] I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Reproducible in:

slackclient version: slackclient==2.7.2

python version: Python 3.6.10

OS version(s): macOS 10.15.5 (19F101)

Steps to reproduce:

from slack import WebClient
client = WebClient(token='XXXX-XXXXXXXXXX-XXXXXXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXX')
response = client.files_upload(channel='XXXXXXXXX', content='Hello world!')

Expected result:

Creation of a snippet containing "Hello world!" on the designated channel.

Actual result:

Nothing appears on the channel while the response looks valid:

response.api_url: 'https://www.slack.com/api/files.upload'
response.data: {
    'ok': True,
    'file': {
        'id': 'XXXXXXXXXXX',
        'created': 1592995530,
        'timestamp': 1592995530,
        'name': '-.txt',
        'title': 'Untitled',
        'mimetype': 'text/plain',
        'filetype': 'text',
        'pretty_type': 'Plain Text',
        'user': 'XXXXXXXXX',
        'editable': True,
        'size': 12,
        'mode': 'snippet',
        'is_external': False,
        'external_type': '',
        'is_public': False,
        'public_url_shared': False,
        'display_as_bot': False,
        'username': '',
        'url_private': 'https://files.slack.com/files-pri/XXXXXXXXX-XXXXXXXXXXX/-.txt',
        'url_private_download': 'https://files.slack.com/files-pri/XXXXXXXXX-XXXXXXXXXXX/download/-.txt',
        'permalink': 'https://XXXapp.slack.com/files/XXXXXXXXX/XXXXXXXXXXX/-.txt',
        'permalink_public': 'https://slack-files.com/XXXXXXXXX-XXXXXXXXXXX-XXXXXXXXXX',
        'edit_link': 'https://XXXapp.slack.com/files/XXXXXXXXX/XXXXXXXXXXX/-.txt/edit',
        'preview': 'Hello world!',
        '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>Hello world!</pre></div>\n</div>\n</div>\n',
        'lines': 1,
        'lines_more': 0,
        'preview_is_truncated': False,
        'comments_count': 0,
        'is_starred': False,
        'shares': {},
        'channels': [],
        'groups': [],
        'ims': [],
        'has_rich_preview': False
    }
}
response.headers: {
    'date': 'Wed, 24 Jun 2020 10:45:30 GMT',
    'server': 'Apache',
    'x-slack-req-id': 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
    'x-oauth-scopes': 'identify,bot:basic',
    'x-accepted-oauth-scopes': 'files:write:user,post',
    'access-control-expose-headers': 'x-slack-req-id, retry-after',
    'x-slack-backend': 'r',
    'x-content-type-options': 'nosniff',
    'expires': 'Mon, 26 Jul 1997 05:00:00 GMT',
    'cache-control': 'private, no-cache, no-store, must-revalidate',
    'x-xss-protection': '0',
    'vary': 'Accept-Encoding',
    'pragma': 'no-cache',
    'access-control-allow-headers': 'slack-route, x-slack-version-ts, x-b3-traceid, x-b3-spanid, x-b3-parentspanid, x-b3-sampled, x-b3-flags',
    'strict-transport-security': 'max-age=31536000; includeSubDomains; preload',
    'referrer-policy': 'no-referrer',
    'access-control-allow-origin': '*',
    'connection': 'close',
    'transfer-encoding': 'chunked',
    'content-type': 'application/json; charset=utf-8',
    'x-via': 'haproxy-www-xvqc'
}
response.http_verb: 'POST'
response.req_args: {
    'headers': {'User-Agent': 'Python/3.6.10 slackclient/2.7.2 Darwin/19.5.0',
    'Content-Type': 'application/x-www-form-urlencoded',
    'Authorization': 'Bearer XXXX-XXXXXXXXXX-XXXXXXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXX'},
    'data': {},
    'params': {'channel': 'XXXXXXXXX', 'content': 'Hello world!'},
    'files': None,
    'json': None
}
response.status_code: 200

Note that, in contrast, this works perfectly fine:

from slack import WebClient
client = WebClient(token='XXXX-XXXXXXXXXX-XXXXXXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXX')
response = client.chat_postMessage(channel='XXXXXXXXX', text='Hello world!')
2x question web-client

Most helpful comment

The parameter name is not channel but channels.
https://api.slack.com/methods/files.upload

All 2 comments

The parameter name is not channel but channels.
https://api.slack.com/methods/files.upload

Indeed... sorry for the noise 馃槙.

Honestly, I think this behaviour is a bit confusing: I would have expected a TypeError for such an unexpected argument; silently ignoring it is not really user friendly. A clear signature for each WebClient's method would be more than welcomed.

Was this page helpful?
0 / 5 - 0 ratings