`WebClient` raises `JSONDecodeError` instead of `SlackApiError` on a malformed JSON body when retry handlers are set
Maintainer antworten meist innerhalb von 1 Tag
@agustin18 arbeitet bereits daran.
Seit 19.11.2026.
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 30/100
Rechercherichtung
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.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Reproducible in
slack_sdkv3.20.0 through v3.47.0 (and currentmain)- Sync
WebClientwith 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.
- Vorherrschende Sprache
- Python
- Sterne
- 4k
- Forks
- 874
- Ø Merge
- 13 Std. 22 Min.
- Gemergte PRs (30 T.)
- 64
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus slackapi/python-slack-sdk
-
SignatureVerifier.is_valid raises instead of returning False for a malformed timestamp, signature or bodyEvtl. vergeben @AmyScript hat das vor 12 Tagen übernommen. Offenbug security semver:patch
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 57/100
slackapi/python-slack-sdk#2067 · 2 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 3/5 Ein halber Tag Anfängerfreundlichkeit 42/100
slackapi/python-slack-sdk#2066 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Add missing Web API methods that are documented on docs.slack.dev to WebClientEvtl. vergeben @zimeg hat das vor 19 Tagen übernommen. Offenenhancement web-client
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 35/100
slackapi/python-slack-sdk#2014 · 2 Kommentare · 2 Reaktionen · 2 zugewiesene Personen ·
Maintainer antworten meist innerhalb von 1 Tag
-
Installation and Bot reject ISO 8601 timestamps with a negative UTC offset or a Z suffixEvtl. vergeben @hello-ashleyintech hat das vor 44 Tagen übernommen. Offenauto-triage-stale bug
slackapi/python-slack-sdk#1989 · 2 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
chat_postMessage silently forwards thread_id to the API, so a threaded reply posts to the channelEvtl. wieder frei Ein Pull Request dazu wurde ohne Merge geschlossen. Offenauto-triage-skip enhancement
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 48/100
slackapi/python-slack-sdk#1923 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in slackapi/python-slack-sdk
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
plone/plone.observability#114 ·
Maintainer antworten meist innerhalb von 1 Tag
-
area:docs type:docs
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
jejjohnson/gauss_flows#246 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
openvax/varcode#824 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Add SAS as a cable typeOffennetbox status: needs triage type: feature
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
netbox-community/netbox#23868 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
emeryberger/CSrankings#15757 ·
Maintainer antworten meist innerhalb von 9 Tagen