解析 GitHub WebHook 负载导致 Json 解码错误

Parsing a GitHub WebHook payload results in Json decode error

解析从 GitHub WebHook 接收到的负载时,遇到这个问题 JSONDecodeError:预期值:第 1 行第 1 列(字符 0)

有效载荷看起来像

payload=%7B%22action%22%3A%22created%22%2C%22issue%22%3A%7B%22url%22%3A%22https%3A%2F%2Fapi.github.com%2Frepos%2FChaiBapchya%2Fincubator-mxnet%2Fissues%2F13%22%2C%22repository_url%22%3A%22https%3A%2F%2Fapi.github.com%2Frepos%2FChaiBapchya%2Fincubator-mxnet%22%2C%22labels_url%22%3A%22https%3A%2F%2Fapi.github.com%2Frepos%2FChaiBapchya%2Fincubator-mxnet%2Fissues%2F13%2Flabels%7B%2Fname%7D%22%2C%22comments_url%22%3A%22https%3A%2F%2Fapi.github.com%2Frepos%2FChaiBapchya%2Fincubator-mxnet%2Fissues%2F13%2Fcomments%22%2C%22events_url%22%3A%22https%3A%2F%2Fapi.github.com%2Frepos%2FChaiBapchya%2Fincubator-mxnet%2Fissues%2F13%2Fevents%22%2C%22html_url%22%3A%22https%3A%2F%2Fgithub.com%2FChaiBapchya%2Fincubator-mxnet%2Fpull%2F13%22%2C%22id%22%3A57165580

错误堆栈跟踪

File "/var/lang/lib/python3.7/json/__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "/var/lang/lib/python3.7/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/var/lang/lib/python3.7/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

仔细查看 GitHub WebHook 配置和负载输出后,发现不匹配。

GitHub WebHook 已配置为在 content type : x-www-form-urlencoded 中传递请求。 此外,有效载荷打印看起来也像 urlencoded 而不是 json.

但是我在 AWS Lambda 中解析 webhook 的辅助函数期待 json。

更改 webhook 成功