`WebClient` raises `JSONDecodeError` instead of `SlackApiError` on a malformed JSON body when retry handlers are set
維護者通常 1 天內回覆
評估
研究方向
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.
由索引模型根據 Issue 內容生成。
描述
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.
- 主要語言
- Python
- 星號
- 4k
- 分支
- 874
- 平均合併
- 13 小時 22 分鐘
- 30 天內合併 PR
- 64
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
slackapi/python-slack-sdk 的其他 Issue
-
SignatureVerifier.is_valid raises instead of returning False for a malformed timestamp, signature or body可能已有人在做 @AmyScript 於 12 天前認領。 未關閉bug security semver:patch
難度 2/5 1-3 小時 新手友好度 57/100
slackapi/python-slack-sdk#2067 · 2 則留言 · 已指派 1 人 ·
維護者通常 1 天內回覆
-
難度 3/5 半天 新手友好度 42/100
slackapi/python-slack-sdk#2066 ·
維護者通常 1 天內回覆
-
Add missing Web API methods that are documented on docs.slack.dev to WebClient可能已有人在做 @zimeg 於 19 天前認領。 未關閉enhancement web-client
難度 4/5 3-5 天 新手友好度 35/100
slackapi/python-slack-sdk#2014 · 2 則留言 · 2 個 reaction · 已指派 2 人 ·
維護者通常 1 天內回覆
-
Installation and Bot reject ISO 8601 timestamps with a negative UTC offset or a Z suffix可能已有人在做 @hello-ashleyintech 於 44 天前認領。 未關閉auto-triage-stale bug
slackapi/python-slack-sdk#1989 · 2 則留言 · 已指派 1 人 ·
維護者通常 1 天內回覆
-
chat_postMessage silently forwards thread_id to the API, so a threaded reply posts to the channel可能重新可做 關聯的 PR 已關閉且未合併。 未關閉auto-triage-skip enhancement
難度 4/5 3-5 天 新手友好度 48/100
slackapi/python-slack-sdk#1923 · 2 則留言 ·
維護者通常 1 天內回覆
查看 slackapi/python-slack-sdk 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 72/100
plone/plone.observability#114 ·
維護者通常 1 天內回覆
-
area:docs type:docs
難度 2/5 1-3 小時 新手友好度 68/100
jejjohnson/gauss_flows#246 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
-
netbox status: needs triage type: feature
難度 2/5 1-3 小時 新手友好度 68/100
netbox-community/netbox#23868 ·
維護者通常 2 天內回覆
-
難度 2/5 1-3 小時 新手友好度 65/100
emeryberger/CSrankings#15757 ·
維護者通常 9 天內回覆