Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error 'no_file_data' in files_upload method when sending binary data in 'file' #728

Closed
4 of 9 tasks
sofya-salmanova opened this issue Jun 22, 2020 · 5 comments · Fixed by #730
Closed
4 of 9 tasks
Assignees
Labels
bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented Version: 2x web-client
Milestone

Comments

@sofya-salmanova
Copy link

Description

Error 'no_file_data' in files_upload method when sending binary data in 'file'

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

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

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

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

Bug Report

Filling out the following details about bugs will help us solve your issue sooner.

Reproducible in:

slackclient version: 2.6.0 and newer

python version: 3.6

OS version(s): Ubuntu 18.04.4

Steps to reproduce:

  1. read file into python bytes
  2. set bytes into 'file' field in files_upload method params
  3. send request to slack

If I use version 2.5.0 (and earlier) -> bug is not reproduced
Setting file path into 'file' instead of bytes also fixes the problem, but I need to send files not saved on the disk, so this is not an acceptable alternative.

Expected result:

File is uploaded

Actual result:

error:
slack.errors.SlackApiError: The request to the Slack API failed.
The server responded with: {'ok': False, 'error': 'no_file_data'}

Attachments:

@seratch seratch self-assigned this Jun 23, 2020
@seratch seratch added the bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented label Jun 23, 2020
@seratch seratch added this to the 2.7.2 milestone Jun 23, 2020
@seratch
Copy link
Member

seratch commented Jun 23, 2020

@sofya-salmanova
Thanks for taking the time to report this and I'm sorry for the inconvenience. As you pointed out, this is an incompatibility issue since v2.6.0. We'll be releasing a new patch version including a fix for it at the latest within a few business days.

As a workaround, utilizing io.BytesIO works for you. If you're in a hurry, please try this workaround out.

import logging
logging.basicConfig(level=logging.DEBUG)

from slack import WebClient
import os
client = WebClient(token=os.environ["SLACK_BOT_TOKEN"])

str = "This is a test"
bytes = bytearray(str, "utf-8")

# This doesn't work with 2.6.0+ as mentioned in this issue
res = client.files_upload(file=bytes, filename="test.txt", filetype="text")

# A workaround
import io
bio = io.BytesIO(bytes)
res = client.files_upload(file=bio, filename="test.txt", filetype="text")

@tplants
Copy link

tplants commented Aug 4, 2020

@seratch's workaround still required on 2.7.3. Is that expected?

@seratch
Copy link
Member

seratch commented Aug 5, 2020

@tplants

This issue is about sending a bytearray object as below. It works already. You don't need to use io.BytesIO anymore.

str = "This is a test"
bytes = bytearray(str, "utf-8")

# This doesn't work with 2.6.0+ as mentioned in this issue
res = client.files_upload(file=bytes, filename="test.txt", filetype="text")

If you're facing a different issue, could you share code reproducing your issue?

@tplants
Copy link

tplants commented Aug 5, 2020

Oh my apologies, I'm dealing with the output of io.BytesIO().getValue() in my code, so something like this:

# this is _bytes_ not a _bytearray_
file = io.BytesIO(bytes_like_object).getValue()

And am seeing the same basic error:

# This worked previously but does not work now.
res = client.files_upload(file=file, filename="test.xlsx", filetype="xlsx")

# This works now.
res = client.files_upload(file=io.BytesIO(file), filename="test.xlsx", filetype="xlsx")

@seratch
Copy link
Member

seratch commented Aug 5, 2020

@tplants thanks for reporting this! I confirmed the issue and will quickly fix it in the next release coming by the end of this week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented Version: 2x web-client
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants