You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've searched for any related issues and avoided creating a duplicate issue.
Bug Report
I am trying to upload a in memory string to slack as a file. Probably something inside of using an io.BytesIO object.
Reproducible in:
slackclient version: 2.5.0
python version: 3.6.10
OS version(s): Docker Alpine
$ cat /etc/alpine-release
3.11.5
Steps to reproduce:
try:
buff=io.BytesIO(b'here is my data but not sure what is wrong.......')
buff.seek(0)
data=FormData()
data.add_field('file', buff, filename='output.txt', content_type='text')
client=slack.WebClient(token=os.environ['SLACK_API_TOKEN'])
response=client.files_upload(channels='#my-random-channel', file=data)
logger.info('html slack post complete %s', response)
exceptExceptionaserr:
logger.exception(err)
Expected result:
What you expected to happen, the file to be uploaded?
Actual result:
response = client.files_upload(channels='#my-random-channel', file=data)
File "/usr/local/lib/python3.6/site-packages/slack/web/client.py", line 970, in files_upload
return self.api_call("files.upload", files={"file": file}, data=kwargs)
File "/usr/local/lib/python3.6/site-packages/slack/web/base_client.py", line 171, in api_call
return self._event_loop.run_until_complete(future)
File "/usr/local/lib/python3.6/asyncio/base_events.py", line 488, in run_until_complete
return future.result()
File "/usr/local/lib/python3.6/site-packages/slack/web/base_client.py", line 226, in _send
return SlackResponse(**{**data, **res}).validate()
File "/usr/local/lib/python3.6/site-packages/slack/web/slack_response.py", line 176, in validate
raise e.SlackApiError(message=msg, response=self)
slack.errors.SlackApiError: The request to the Slack API failed.
The server responded with: {'ok': False, 'error': 'no_file_data'}
Attachments:
Logs, screenshots, screencast, sample project, funny gif, etc.
The text was updated successfully, but these errors were encountered:
Do you have some reason to directly use aiohttp.FormData to construct the form data? If not, just passing io.BytesIO data as file parameter works for you. Here is a minimum working example.
importioimportloggingimportoslogger=logging.getLogger(__name__)
bot_token=os.environ["SLACK_BOT_TOKEN"]
client: WebClient=WebClient(token=bot_token)
channel_ids=self.sync_client, self.logger, ",".join(["C123456789"])
buff=io.BytesIO(b'here is my data but not sure what is wrong.......')
buff.seek(0)
upload=client.files_upload(
file=buff,
filename="output.text",
filetype="text",
channels=channel_ids,
)
logger.debug("File uploaded - %s", upload)
If you need to use aiohttp.FormData for some reason, unfortunately, the WebClient doesn't accept the value and we're not planning to support the type.
seratch
added a commit
to seratch/python-slack-sdk
that referenced
this issue
Apr 21, 2020
Description
Describe your issue here.
What type of issue is this? (place an
x
in one of the[ ]
)Requirements (place an
x
in each of the[ ]
)Bug Report
I am trying to upload a in memory string to slack as a file. Probably something inside of using an io.BytesIO object.
Reproducible in:
slackclient version: 2.5.0
python version: 3.6.10
OS version(s): Docker Alpine
Steps to reproduce:
Expected result:
What you expected to happen, the file to be uploaded?
Actual result:
Attachments:
Logs, screenshots, screencast, sample project, funny gif, etc.
The text was updated successfully, but these errors were encountered: