`WebClient` raises `JSONDecodeError` instead of `SlackApiError` on a malformed JSON body when retry handlers are set

Ouverte
#2,070 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

@agustin18 y travaille déjà.

Depuis le 19/11/2026.

  • #2072 par @agustin18 — ouverte
  • #2073 par @tony1233200 — fermée sans fusion

Évaluation

Difficulté
2/5
Temps estimé
1-3 heures
Accessibilité débutants
30/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
À l'abandon
Stack technique
python
Domaine
backend

Piste de recherche

Start by reading _perform_urllib_http_request and _urllib_api_call, then inspect the tests covering malformed response bodies and retry handlers. Reproduce the provided WebClient example and compare it with WebClient(retry_handlers=[]). Done means malformed JSON follows the existing fallback and raises SlackApiError; consider whether _request_for_pagination needs the same treatment, as the issue notes.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

bug semver:major web-client
Reproducible in
  • slack_sdk v3.20.0 through v3.47.0 (and current main)
  • Sync WebClient with retry handlers set (the default)
Steps to reproduce
from unittest.mock import patch
from slack_sdk import WebClient

client = WebClient(token="xoxb-test")
response = {"status": 200, "headers": {}, "body": '{"ok": tru'}
with patch.object(client, "_perform_urllib_http_request_internal", return_value=response):
    client.api_test()
Expected result

A SlackApiError whose response["error"] starts with Received a response in a non-JSON format. That is what WebClient(retry_handlers=[]), AsyncWebClient, and v3.19.5 and earlier raise for the same body.

Actual result

json.decoder.JSONDecodeError: Expecting value: line 1 column 8 (char 7), logged at ERROR as Failed to send a request to Slack API server.

Cause

#1334 (v3.20.0) added a json.loads to the retry loop in _perform_urllib_http_request. It parses any 200 body that starts with { and has no guard. A decode error escapes through the except Exception branch before the graceful fallback in _urllib_api_call runs. Bodies that don't start with {, and clients without retry handlers, still get SlackApiError.

Proposed fix

Catch JSONDecodeError in that retry-branch parse and leave parsed_body unset. _urllib_api_call then takes its existing fallback. About 3 lines plus a test.

Why 4.x

This has shipped since v3.20.0, so callers may catch JSONDecodeError or ValueError around sync calls. Changing the raised type would break them. _request_for_pagination also raises JSONDecodeError on a malformed body, with or without handlers, so it's worth deciding there in the same change.

Langage dominant
Python
Étoiles
4k
Forks
874
Merge moyen
13 h 22 min
PR mergées (30 j)
64

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de slackapi/python-slack-sdk

Toutes les issues de slackapi/python-slack-sdk

Issues similaires

Plus d'issues Python

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.