Skip to content

Unable to handle ratelimited #805

@rcsrao

Description

@rcsrao
while True:
  try:
    response = send_slack_message(channel, message)
  except SlackApiError as e:
    if e.response["error"] == "ratelimited":
      # The `Retry-After` header will tell you how long to wait before retrying
      delay = int(e.response.headers['Retry-After'])
      print(f"Rate limited. Retrying in {delay} seconds")
      time.sleep(delay)
      response = send_slack_message(channel, message)
    else:
      # other errors
      raise e

This is helpless it seems,

**During handling of the above exception, another exception occurred:**

Traceback (most recent call last):
  File "/usr/local/Cellar/python@3.8/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/usr/local/Cellar/python@3.8/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "dpxbot.py", line 146, in process_message
    self.hello(message) 
  File "dpxbot.py", line 189, in hello
    response = self.send_slack_message(message, slack_ts, user_id, channel_id)
  File "dpxbot.py", line 212, in send_slack_message
    rep = self.web_client.chat_postMessage(
  File "/usr/local/lib/python3.8/site-packages/slack/web/client.py", line 1041, in chat_postMessage
    return self.api_call("chat.postMessage", json=kwargs)
  File "/usr/local/lib/python3.8/site-packages/slack/web/base_client.py", line 150, in api_call
    return self._sync_send(api_url=api_url, req_args=req_args)
  File "/usr/local/lib/python3.8/site-packages/slack/web/base_client.py", line 241, in _sync_send
    return self._urllib_api_call(
  File "/usr/local/lib/python3.8/site-packages/slack/web/base_client.py", line 369, in _urllib_api_call
    return SlackResponse(
  File "/usr/local/lib/python3.8/site-packages/slack/web/slack_response.py", line 194, 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': 'ratelimited'}

Any help would be appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions