slackapi/python-slack-sdk

`files_upload_v2` returning 500 Internal Server Error

crwgregory opened this issue · 10 comments

Reproducible in:

The Slack SDK version

slack-sdk==3.21.3

Python runtime version

Python 3.10.12

OS info

ProductName: macOS
ProductVersion: 13.4.1
ProductVersionExtra: (c)
BuildVersion: 22F770820d
Darwin Kernel Version 22.5.0: Thu Jun 8 22:22:23 PDT 2023; root:xnu-8796.121.3~7/RELEASE_ARM64_T6020

Steps to reproduce:

import urllib.error
from slack_sdk import WebClient
from slack_sdk.errors import SlackApiError

token = "abcd-token"
client = WebClient(token=token)

channel_id = "abcd-channelid"


def main():
    try:
        response = client.files_upload_v2(
            channel=channel_id,
            title="hello",
            content="world",
            initial_comment="testing",
        )
        print(response)
    except SlackApiError as e:
        print(f"SlackApiError: Error uploading file: {e}")
        raise e
    except urllib.error.HTTPError as e:
        print(f"HTTPError: Error uploading file: {e}")
        raise e


if __name__ == "__main__":
    main()

Also tested in a docker container on amd64:

requirements.txt

boto3==1.26.161
botocore==1.29.161
certifi==2023.5.7
charset-normalizer==3.1.0
exceptiongroup==1.1.1
idna==3.4
iniconfig==2.0.0
jmespath==1.0.1
packaging==23.1
pluggy==1.2.0
pytest==7.4.0
python-dateutil==2.8.2
requests==2.31.0
s3transfer==0.6.1
six==1.16.0
slack-sdk==3.21.3
tomli==2.0.1
urllib3==1.26.16

Dockerfile

FROM --platform=linux/amd64 python:3.10

WORKDIR /usr/src/app

COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt

COPY . .

CMD [ "python", "./app.py" ]
docker build -t slack-error .
docker run -it --rm --name slack-error-app slack-error

Output:

HTTPError: Error uploading file: HTTP Error 500: Internal Server Error
Traceback (most recent call last):
  File "/usr/src/app/./app.py", line 29, in <module>
    main()
  File "/usr/src/app/./app.py", line 25, in main
    raise e
  File "/usr/src/app/./app.py", line 13, in main
    response = client.files_upload_v2(
  File "/usr/local/lib/python3.10/site-packages/slack_sdk/web/client.py", line 3228, in files_upload_v2
    upload_result = _upload_file_via_v2_url(
  File "/usr/local/lib/python3.10/site-packages/slack_sdk/web/internal_utils.py", line 384, in _upload_file_via_v2_url
    resp = urlopen(req, context=ssl, timeout=timeout)  # skipcq: BAN-B310
  File "/usr/local/lib/python3.10/urllib/request.py", line 216, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/local/lib/python3.10/urllib/request.py", line 525, in open
    response = meth(req, response)
  File "/usr/local/lib/python3.10/urllib/request.py", line 634, in http_response
    response = self.parent.error(
  File "/usr/local/lib/python3.10/urllib/request.py", line 563, in error
    return self._call_chain(*args)
  File "/usr/local/lib/python3.10/urllib/request.py", line 496, in _call_chain
    result = func(*args)
  File "/usr/local/lib/python3.10/urllib/request.py", line 643, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 500: Internal Server Error

Expected result:

Either a success message posted to channel as a file, or a clear error message on what is failing.

Actual result:

python app.py
HTTPError: Error uploading file: HTTP Error 500: Internal Server Error
Traceback (most recent call last):
  File "/Users/cg/dev/marrick/slack/file-upload-error/app.py", line 32, in <module>
    main()
  File "/Users/cg/dev/marrick/slack/file-upload-error/app.py", line 28, in main
    raise e
  File "/Users/cg/dev/marrick/slack/file-upload-error/app.py", line 16, in main
    response = client.files_upload_v2(
  File "/Users/cg/anaconda3/envs/marrick-slack-bot/lib/python3.10/site-packages/slack_sdk/web/client.py", line 3228, in files_upload_v2
    upload_result = _upload_file_via_v2_url(
  File "/Users/cg/anaconda3/envs/marrick-slack-bot/lib/python3.10/site-packages/slack_sdk/web/internal_utils.py", line 384, in _upload_file_via_v2_url
    resp = urlopen(req, context=ssl, timeout=timeout)  # skipcq: BAN-B310
  File "/Users/cg/anaconda3/envs/marrick-slack-bot/lib/python3.10/urllib/request.py", line 216, in urlopen
    return opener.open(url, data, timeout)
  File "/Users/cg/anaconda3/envs/marrick-slack-bot/lib/python3.10/urllib/request.py", line 525, in open
    response = meth(req, response)
  File "/Users/cg/anaconda3/envs/marrick-slack-bot/lib/python3.10/urllib/request.py", line 634, in http_response
    response = self.parent.error(
  File "/Users/cg/anaconda3/envs/marrick-slack-bot/lib/python3.10/urllib/request.py", line 563, in error
    return self._call_chain(*args)
  File "/Users/cg/anaconda3/envs/marrick-slack-bot/lib/python3.10/urllib/request.py", line 496, in _call_chain
    result = func(*args)
  File "/Users/cg/anaconda3/envs/marrick-slack-bot/lib/python3.10/urllib/request.py", line 643, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 500: Internal Server Error
make: *** [run] Error 

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.

Just for some additional context, the endpoint was working properly in our Lambda function on August 2nd. We didn't make any calls on Aug 3rd, and today we are getting the 500 response. So something changed on the backend between the 2nd and today.

Yup, having the same issue. Tested it in GCP and locally.

Are you seeing this issue every time / still? I just checked with the Files team and their health dashboard shows a drop in reliability yesterday, but it has bounced back to nominal numbers now.

Seems to be working again now. Had a few hiccups 40 minutes ago. But seems a bit more stable again rn.

Which client are you uploading from? To be fair, the reliability seems to be higher on desktop in general than on mobile, though yesterday's blip dropped reliability by a few percentage points across the board in all clients.

I am uploading files from my python bot that uses slack_bolt.

Right.. of course.. silly me 🤪

It's worth noting the Slack back-end was having issues with file uploads today.

(I have a #slack-alerts channel set up to post from the Slack Status RSS feed to keep me apprised of such things.)

Thanks for that tip, will probably set that up as well. Seems quite handy to have.

Thank you! Will close the issue as it's not related to the sdk and the service is functioning normally now. 🧀