Error 'no_file_data' in files_upload method when sending binary data in 'file'
x in one of the [ ])x in each of the [ ])Filling out the following details about bugs will help us solve your issue sooner.
slackclient version: 2.6.0 and newer
python version: 3.6
OS version(s): Ubuntu 18.04.4
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.
File is uploaded
error:
slack.errors.SlackApiError: The request to the Slack API failed.
The server responded with: {'ok': False, 'error': 'no_file_data'}
@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")
@seratch's workaround still required on 2.7.3. Is that expected?
@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?
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")
@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.