python-slack-sdk: File Upload API succeeds despite 408 Request Timeout
Reproducible in:
# test.py
import sys
# Enable debug logging
import logging
from slack_sdk import WebClient
def uploadToSlackChannel():
client = WebClient(
token="you-slack-token", timeout=300)
try:
filepath = "file-to-upload"
response = client.files_upload(
channels="your-slack-channel-name", file=filepath)
assert response["file"] # the uploaded file
except Exception as e:
print(e)
uploadToSlackChannel()
The Slack SDK version
slack-sdk==3.13.0
Python runtime version
Python 3.9.10
OS info
ProductName: Mac OS X ProductVersion: 10.15.7 BuildVersion: 19H1615 Darwin Kernel Version 19.6.0: Sun Nov 14 19:58:51 PST 2021; root:xnu-6153.141.50~1/RELEASE_X86_64
Steps to reproduce:
(Share the commands to run, source code, and project settings (e.g., setup.py))
- copy the above snippet to any file (e.g. upload_to_slack.py)
- run
python3 upload_to_slack.py
Expected result:
Should succeed without any error
Actual result:
The file gets uploaded but also throws this error
Received a response in a non-JSON format: stream timeout
The server responded with: {'status': 408, 'headers': {'x-edge-backend': 'envoy-www', 'content-length': '14', 'content-type': 'text/plain', 'x-slack-edge-shared-secret-outcome': 'no-match', 'date': 'Wed, 26 Jan 2022 07:12:45 GMT', 'server': 'envoy', 'via': 'envoy-edge-bom-jbcm', 'connection': 'close'}, 'body': 'stream timeout'}
Requirements
For general questions/issues about Slack API platform or its server-side, could you submit questions at https://my.slack.com/help/requests/new instead. š
Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to those rules.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 19
- Comments: 57 (9 by maintainers)
Please, priorotize
Iām using
curl
for uploading file and had the same problem. What worked as a workaround is adding:--limit-rate 5M
.@vishim I know that we are very slow on this but we are still waiting for the progress on the backend engineering side. Once we get the updates that we can publicly share, we will update yāall here.
Having this issue on a node project using the Bolt API, yesterday it worked. Today, itās failing with 408ās for every single file, nothing succeeds regardless of how many times Bolt retries. File size is only in the 1-2 MB range. Tried switching to Axios to run upload requests instead, same issue. Update - definitely an intermittent issue. Another day later and I donāt see any 408ās at all.
Facing the same issue, trying to upload 60MB file using curl request, failing with stream timeout error.
Thankyou š
That moment, when a guy from comments helped more than an official support
Hi all, let me share some updates on this issue.
Firstly, sincere apologies for taking a long time to resolve this issue on the Slack platform side. We do understand that this issue has been critical for many people.
As a solution, we just released v3.19.0, which includes a new method named
WebClient#files_upload_v2()
. This new method is much stabler and is mostly compatible with the existingfiles_upload()
method. Please migrate to the new method if your app is affected by the server-side performance issue described here. Here is an example code demonstrating how to use the v2 method:The new method eliminates the timeouts. In addition, it enables 3rd party app developers to upload multiple files like humans do in Slack clients. This feature addition can be useful for many use cases. Here is a simple example code:
Please refer to the release notes for more details: https://github.com/slackapi/python-slack-sdk/releases/tag/v3.19.0
I tried to throttle using OkHttp to 500KB/Sec and yet the issue persists for me when uploading 40MB files from the API. Oddly enough we can upload the same files using the slack desktop/android apps without any issues. This issue is so frustrating!
Even we are facing the same issue @seratch. We are not able to upload build artefacts to slack š¢
Keeping you in the loop here @jaypoojara. Letās follow this thread.
curl https://slack.com/api/files.upload --limit-rate 423K -F token=āxoxb-PUT-YOUR-TOKEN-HEREā -F channels=ā#test-channelā -F title=āTESTING! FileName.apkā -F filename=āfilename.txtā -F file=ā@/path/to/file/test_empty_file.txtā
Maybe a temporary workaround for those who are experiencing this issue intermittently. It retries three times each with a
3s
pause.Edit: We have been using the above for a week now. Normally it does not need more than one try. But occasionally it goes up to three tries, with the third try succeeding.
Is there any correlation with file type? This started happening to us with ~33MB zip file.
Larger text (csv) files never had this issueā¦but our CSVs hit a ridiculous size and we started zipping them when they were over some threshold and then we started getting this issue. Makes me suspicious that this might relate to file-type rather than just raw size.
Can anyone else commend on the file types you are experiencing the problem with (binary vs text and also mime-type)? Maybe there is a correlation that will make this easier for the devs to repro.
@locomike Iām sorry to say this but I donāt have anything further that I can suggest at this moment. We will continue communicating with the server-side teams.
@iamarjun Thanks for sharing more details!
Iāve checked internal reports and found that other people are also facing this server-side issue with relatively large size files (I know that your file is not so large but it seems that the situation can arise even with mega-byte-level size).
The server-side engineering teams are working hard to eliminate (at least mitigate) the issue now but I cannot tell when the situation can be improved.
The only workaround that I can suggest is that, if you receive the 408 error, your app can check files.list API results with the same token to know whether the upload was actually successful. If there is no new item in the response, your app needs to retry the same files.upload API call.
Weāre sorry for the disruption.
Hi @seratch hereās the full log using curl
curl -v https://slack.com/api/files.upload -F token=access-token -F channels= "#ios-ajay-test1" -F file=@file_path