MCPcopy Create free account
hub / github.com/slackapi/python-slack-sdk / _perform_http_request

Method _perform_http_request

slack_sdk/scim/v1/client.py:268–389  ·  view source on GitHub ↗
(
        self,
        *,
        http_verb: str = "GET",
        url: str,
        body: Optional[Dict[str, Any]] = None,
        headers: Dict[str, str],
    )

Source from the content-addressed store, hash-verified

266 )
267
268 def _perform_http_request(
269 self,
270 *,
271 http_verb: str = "GET",
272 url: str,
273 body: Optional[Dict[str, Any]] = None,
274 headers: Dict[str, str],
275 ) -> SCIMResponse:
276 if body is not None:
277 if body.get("schemas") is None:
278 body["schemas"] = ["urn:scim:schemas:core:1.0"]
279 body = json.dumps(body)
280 headers["Content-Type"] = "application/json;charset=utf-8"
281
282 if self.logger.level <= logging.DEBUG:
283 headers_for_logging = {k: "(redacted)" if k.lower() == "authorization" else v for k, v in headers.items()}
284 self.logger.debug(f"Sending a request - {http_verb} url: {url}, body: {body}, headers: {headers_for_logging}")
285
286 # NOTE: Intentionally ignore the `http_verb` here
287 # Slack APIs accepts any API method requests with POST methods
288 req = Request(
289 method=http_verb,
290 url=url,
291 data=body.encode("utf-8") if body is not None else None,
292 headers=headers,
293 )
294 resp = None
295 last_error = None
296
297 retry_state = RetryState()
298 counter_for_safety = 0
299 while counter_for_safety < 100:
300 counter_for_safety += 1
301 # If this is a retry, the next try started here. We can reset the flag.
302 retry_state.next_attempt_requested = False
303
304 try:
305 resp = self._perform_http_request_internal(url, req)
306 # The resp is a 200 OK response
307 return resp
308
309 except HTTPError as e:
310 # read the response body here
311 charset = e.headers.get_content_charset() or "utf-8"
312 response_body: str = e.read().decode(charset)
313 # As adding new values to HTTPError#headers can be ignored, building a new dict object here
314 response_headers = dict(e.headers.items())
315 resp = SCIMResponse(
316 url=url,
317 status_code=e.code,
318 raw_body=response_body,
319 headers=response_headers,
320 )
321 if e.code == 429:
322 # for backward-compatibility with WebClient (v.2.5.0 or older)
323 if "retry-after" not in resp.headers and "Retry-After" in resp.headers:
324 resp.headers["retry-after"] = resp.headers["Retry-After"]
325 if "Retry-After" not in resp.headers and "retry-after" in resp.headers:

Callers 1

api_callMethod · 0.95

Calls 9

RetryStateClass · 0.90
SCIMResponseClass · 0.85
can_retryMethod · 0.80
_debug_log_responseFunction · 0.70
getMethod · 0.45
debugMethod · 0.45

Tested by

no test coverage detected