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
With the default settings, only ``ConnectionErrorRetryHandler`` with its default configuration (=only one retry in the manner of `exponential backoff and jitter <https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/>`_ is enabled. The retry handler retries if an API client encounters a connectivity-related failure (e.g., Connection reset by peer).
59
+
60
+
To use other retry handlers, you can pass a list of ``RetryHandler`` to the client constructor. For instance, you can add the built-in ``RateLimitErrorRetryHandler`` this way:
Creating your own ones is also quite simple. Defining a new class that inherits ``slack_sdk.http_retry.RetryHandler`` (``AsyncRetryHandler`` for asyncio apps) and implements required methods (internals of ``can_retry`` / ``prepare_for_next_retry``). Check the built-in ones' source code for learning how to properly implement.
76
+
77
+
.. code-block:: python
78
+
79
+
import socket
80
+
from typing import Optional
81
+
from slack_sdk.http_retry import (RetryHandler, RetryState, HttpRequest, HttpResponse)
82
+
from slack_sdk.http_retry.builtin_interval_calculators import BackoffRetryIntervalCalculator
83
+
from slack_sdk.http_retry.jitter import RandomJitter
84
+
85
+
classMyRetryHandler(RetryHandler):
86
+
def_can_retry(
87
+
self,
88
+
*,
89
+
state: RetryState,
90
+
request: HttpRequest,
91
+
response: Optional[HttpResponse] =None,
92
+
error: Optional[Exception] =None
93
+
) -> bool:
94
+
# [Errno 104] Connection reset by peer
95
+
return error isnotNoneandisinstance(error, socket.error) and error.errno ==104
96
+
97
+
client = AuditLogsClient(
98
+
token=os.environ["SLACK_ORG_ADMIN_USER_TOKEN"],
99
+
retry_handlers=[MyRetryHandler()],
100
+
)
101
+
102
+
For asyncio apps, ``Async`` prefixed corresponding modules are available. All the methods in those methods are async/await compatible. Check `the source code <https://github.com/slackapi/python-slack-sdk/blob/main/slack_sdk/http_retry/async_handler.py>`_ and `tests <https://github.com/slackapi/python-slack-sdk/blob/main/tests/slack_sdk_async/web/test_async_web_client_http_retry.py>`_ for more details.
Copy file name to clipboardExpand all lines: docs-src/oauth/index.rst
+31-1Lines changed: 31 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -236,5 +236,35 @@ You can use the same ``InstallationStore`` in the Slack event handler.
236
236
237
237
Again, if you're looking for an easier solution, take a look at `Bolt for Python <https://github.com/slackapi/bolt-python>`_. With Bolt, you don't need to implement most of the above code on your own.
238
238
239
+
Sign in with Slack
240
+
*************************************************
241
+
242
+
`Sign in with Slack <https://api.slack.com/authentication/sign-in-with-slack>`_ helps users log into your service using their Slack profile. The platform feature was recently upgraded to be compatible with the standard `OpenID Connect <https://openid.net/connect/>`_ specification. With slack-sdk v3.9+, implementing the auth flow is much easier.
243
+
244
+
When you create a new Slack app, set the following user scopes:
245
+
246
+
.. code-block:: yaml
247
+
248
+
oauth_config:
249
+
redirect_urls:
250
+
- https://{your-domain}/slack/oauth_redirect
251
+
scopes:
252
+
user:
253
+
- openid # required
254
+
- email # optional
255
+
- profile # optional
256
+
257
+
Check `the Flask app example <https://github.com/slackapi/python-slack-sdk/blob/main/integration_tests/samples/openid_connect/flask_example.py>`_ to learn how to implement your Web app that handles the OpenID Connect flow with end-users. It does the following:
258
+
259
+
**Build the OpenID Connect authorize URL**
260
+
261
+
- ``slack_sdk.oauth.OpenIDConnectAuthorizeUrlGenerator`` helps you easily do this
262
+
- ``slack_sdk.oauth.OAuthStateStore`` is still available for generating ``state`` parameter value. It's available for ``nonce`` management too.
263
+
264
+
**openid.connect.* API calls**
265
+
266
+
``WebClient`` can perform ``openid.connect.token`` API calls with given ``code`` parameter
267
+
268
+
If you want to know the way with asyncio, check `the Sanic app example <https://github.com/slackapi/python-slack-sdk/blob/main/integration_tests/samples/openid_connect/sanic_example.py>`_ in the same directory.
With the default settings, only ``ConnectionErrorRetryHandler`` with its default configuration (=only one retry in the manner of `exponential backoff and jitter <https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/>`_ is enabled. The retry handler retries if an API client encounters a connectivity-related failure (e.g., Connection reset by peer).
107
+
108
+
To use other retry handlers, you can pass a list of ``RetryHandler`` to the client constructor. For instance, you can add the built-in ``RateLimitErrorRetryHandler`` this way:
Creating your own ones is also quite simple. Defining a new class that inherits ``slack_sdk.http_retry.RetryHandler`` (``AsyncRetryHandler`` for asyncio apps) and implements required methods (internals of ``can_retry`` / ``prepare_for_next_retry``). Check the built-in ones' source code for learning how to properly implement.
124
+
125
+
.. code-block:: python
126
+
127
+
import socket
128
+
from typing import Optional
129
+
from slack_sdk.http_retry import (RetryHandler, RetryState, HttpRequest, HttpResponse)
130
+
from slack_sdk.http_retry.builtin_interval_calculators import BackoffRetryIntervalCalculator
131
+
from slack_sdk.http_retry.jitter import RandomJitter
132
+
133
+
classMyRetryHandler(RetryHandler):
134
+
def_can_retry(
135
+
self,
136
+
*,
137
+
state: RetryState,
138
+
request: HttpRequest,
139
+
response: Optional[HttpResponse] =None,
140
+
error: Optional[Exception] =None
141
+
) -> bool:
142
+
# [Errno 104] Connection reset by peer
143
+
return error isnotNoneandisinstance(error, socket.error) and error.errno ==104
144
+
145
+
client = SCIMClient(
146
+
token=os.environ["SLACK_ORG_ADMIN_USER_TOKEN"],
147
+
retry_handlers=[MyRetryHandler()],
148
+
)
149
+
150
+
For asyncio apps, ``Async`` prefixed corresponding modules are available. All the methods in those methods are async/await compatible. Check `the source code <https://github.com/slackapi/python-slack-sdk/blob/main/slack_sdk/http_retry/async_handler.py>`_ and `tests <https://github.com/slackapi/python-slack-sdk/blob/main/tests/slack_sdk_async/web/test_async_web_client_http_retry.py>`_ for more details.
Copy file name to clipboardExpand all lines: docs-src/web/index.rst
+56-1Lines changed: 56 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -590,7 +590,9 @@ Here's a very basic example of how one might deal with rate limited requests.
590
590
# other errors
591
591
raise e
592
592
593
-
See the documentation on `Rate Limiting <https://api.slack.com/docs/rate-limits>`_ for more info.
593
+
Since v3.9.0, the built-in ``RateLimitErrorRetryHandler`` is available as an easier way to do the retries for rate limited errors. Refer to the RetryHandler section in this page for more details.
594
+
595
+
To learn the Slack rate limits in general, see the documentation on `Rate Limiting <https://api.slack.com/docs/rate-limits>`_.
594
596
595
597
--------
596
598
@@ -649,4 +651,57 @@ All the API methods are available in asynchronous programming using the standard
With the default settings, only ``ConnectionErrorRetryHandler`` with its default configuration (=only one retry in the manner of `exponential backoff and jitter <https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/>`_ is enabled. The retry handler retries if an API client encounters a connectivity-related failure (e.g., Connection reset by peer).
661
+
662
+
To use other retry handlers, you can pass a list of ``RetryHandler`` to the client constructor. For instance, you can add the built-in ``RateLimitErrorRetryHandler`` this way:
Creating your own ones is also quite simple. Defining a new class that inherits ``slack_sdk.http_retry.RetryHandler`` (``AsyncRetryHandler`` for asyncio apps) and implements required methods (internals of ``can_retry`` / ``prepare_for_next_retry``). Check the built-in ones' source code for learning how to properly implement.
678
+
679
+
.. code-block:: python
680
+
681
+
import socket
682
+
from typing import Optional
683
+
from slack_sdk.http_retry import (RetryHandler, RetryState, HttpRequest, HttpResponse)
684
+
from slack_sdk.http_retry.builtin_interval_calculators import BackoffRetryIntervalCalculator
685
+
from slack_sdk.http_retry.jitter import RandomJitter
686
+
687
+
classMyRetryHandler(RetryHandler):
688
+
def_can_retry(
689
+
self,
690
+
*,
691
+
state: RetryState,
692
+
request: HttpRequest,
693
+
response: Optional[HttpResponse] =None,
694
+
error: Optional[Exception] =None
695
+
) -> bool:
696
+
# [Errno 104] Connection reset by peer
697
+
return error isnotNoneandisinstance(error, socket.error) and error.errno ==104
698
+
699
+
client = WebClient(
700
+
token=os.environ["SLACK_BOT_TOKEN"],
701
+
retry_handlers=[MyRetryHandler()],
702
+
)
703
+
704
+
For asyncio apps, ``Async`` prefixed corresponding modules are available. All the methods in those methods are async/await compatible. Check `the source code <https://github.com/slackapi/python-slack-sdk/blob/main/slack_sdk/http_retry/async_handler.py>`_ and `tests <https://github.com/slackapi/python-slack-sdk/blob/main/tests/slack_sdk_async/web/test_async_web_client_http_retry.py>`_ for more details.
With the default settings, only ``ConnectionErrorRetryHandler`` with its default configuration (=only one retry in the manner of `exponential backoff and jitter <https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/>`_ is enabled. The retry handler retries if an API client encounters a connectivity-related failure (e.g., Connection reset by peer).
116
+
117
+
To use other retry handlers, you can pass a list of ``RetryHandler`` to the client constructor. For instance, you can add the built-in ``RateLimitErrorRetryHandler`` this way:
Creating your own ones is also quite simple. Defining a new class that inherits ``slack_sdk.http_retry.RetryHandler`` (``AsyncRetryHandler`` for asyncio apps) and implements required methods (internals of ``can_retry`` / ``prepare_for_next_retry``). Check the built-in ones' source code for learning how to properly implement.
133
+
134
+
.. code-block:: python
135
+
136
+
import socket
137
+
from typing import Optional
138
+
from slack_sdk.http_retry import (RetryHandler, RetryState, HttpRequest, HttpResponse)
139
+
from slack_sdk.http_retry.builtin_interval_calculators import BackoffRetryIntervalCalculator
140
+
from slack_sdk.http_retry.jitter import RandomJitter
141
+
142
+
classMyRetryHandler(RetryHandler):
143
+
def_can_retry(
144
+
self,
145
+
*,
146
+
state: RetryState,
147
+
request: HttpRequest,
148
+
response: Optional[HttpResponse] =None,
149
+
error: Optional[Exception] =None
150
+
) -> bool:
151
+
# [Errno 104] Connection reset by peer
152
+
return error isnotNoneandisinstance(error, socket.error) and error.errno ==104
153
+
154
+
webhook = WebhookClient(
155
+
url=url,
156
+
retry_handlers=[MyRetryHandler()],
157
+
)
158
+
159
+
For asyncio apps, ``Async`` prefixed corresponding modules are available. All the methods in those methods are async/await compatible. Check `the source code <https://github.com/slackapi/python-slack-sdk/blob/main/slack_sdk/http_retry/async_handler.py>`_ and `tests <https://github.com/slackapi/python-slack-sdk/blob/main/tests/slack_sdk_async/web/test_async_web_client_http_retry.py>`_ for more details.
0 commit comments