GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — `WebClient` raises `JSONDecodeError` instead of `SlackApiError` on a malformed JSON body when retry handlers are set · Issue #2070 · slackapi/python-slack-sdk

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

New issue
Copy link
New issue
Copy link
Open
#2072
Open
WebClient raises JSONDecodeError instead of SlackApiError on a malformed JSON body when retry handlers are set#2070
#2072
Copy link
Labels
bugM-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documentedsemver:majorweb-client
Milestone
4.x

Description

@WilliamBergamin
WilliamBergamin
opened on Nov 19, 2026
Issue body actions

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.

Activity

  1. WilliamBergamin
    added this to the 4.x milestone on Nov 19, 2026
  2. WilliamBergamin
    added
    bugM-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented
    semver:major
    web-client
    on Nov 19, 2026
  3. eejd
    added a commit that references this issue on Nov 22, 2026

    Test non-JSON 200 responses raise SlackApiError with and without retr…

    ad53d67
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugM-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documentedsemver:majorweb-client

    Type

    No type

    Projects

    No projects

      Milestone

      • 4.xNo due date

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.