Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

SlackApiError cannot be unpickled

未关闭
#1,291 6 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
python
领域
api

调研方向

从 SlackApiError 的定义开始,在 Python 3.11 上运行 issue 中所示的 pickle 复现。检查异常的初始化和表示方式,然后验证 pickling 和 unpickling 能够保留消息和响应,且不会引发 TypeError。

由索引模型根据 Issue 内容生成。

描述

auto-triage-skip enhancement question web-client

SlackApiError raises an error when trying to unpickle it.

This is particularly annoying in a Celery task since another bug in celery will cause the whole worker node to fail.

The Slack SDK version

2.9.4

Python runtime version

3.11.0

OS info

ProductName: macOS
ProductVersion: 13.0
BuildVersion: 22A380
Darwin Kernel Version 22.1.0: Sun Oct 9 20:15:09 PDT 2022; root:xnu-8792.41.9~2/RELEASE_ARM64_T6000

Steps to reproduce:
import pickle
from slack.errors import SlackApiError

e = SlackApiError("Internal server error", "<response>")

dumped = pickle.dumps(e)
pickle.loads(dumped) 
Expected result:

No error.

Actual result:
Traceback (most recent call last):
  File "/private/tmp/pickle_exc/bug.py", line 7, in <module>
    pickle.loads(dumped)
TypeError: SlackApiError.__init__() missing 1 required positional argument: 'response'
Solution

The SlackApiError could be implemented in such a way that the constructor accepts only the message, and the response defaults to None. Then the string representation can be delegated to __str__:

class SlackApiError(Exception):

    def __init__(self, message, response=None):
        super().__init__(message)
        self.response = response
    
    def __str__(self):
        return f"{self.args[0]}\nThe server responded with: {self.response}"
主要语言
Python
星标
4k
派生
857
平均合并
22 小时 21 分钟
30 天内合并 PR
16

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

slackapi/python-slack-sdk 的其他 Issue

查看 slackapi/python-slack-sdk 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。