-1

Started using Slack API for Python, got comfortable using it from their documentation. I couldn't understand how this is working under the hood

Slack API returns SlackResponse object in case of a failure (or success as well), and it will look something like this

slack-api-error

Now if I run

e.response["error"]

it prints 'channel_not_found' message - as a str object

Thought "error" is a key (as in e.response as a dict), and tried to print all the available keys, but it's not a dict/hash it seems

e.response.keys()
# AttributeError: 'SlackResponse' object has no attribute 'keys'

Can someone explain how this is possible please. Would love to understand how they made this possible. TIA

Quantum
  • 510
  • 1
  • 2
  • 19
scorpion35
  • 944
  • 2
  • 12
  • 30

1 Answers1

2

(Its always worth it to take a look at the source code, especially with python.

Here you can see that it returns a string, because the getter methods are overridden (__getitem__here), in case I understand your question correctly: https://github.com/slackapi/python-slack-sdk/blob/main/slack_sdk/web/slack_response.py

NoBlockhit
  • 369
  • 2
  • 15
  • That makes sense. Thank you for taking time to look up their api and answer my question – scorpion35 Jun 07 '23 at 12:06
  • 1
    Absolutely no problem. Please just try to give your question a more meaningful title, because people dont click on it otherwise. – NoBlockhit Jun 07 '23 at 12:19