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

问题描述 投票:0回答:1

当解析从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)

python json github aws-lambda git-webhooks
1个回答
0
投票

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

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

但是我在AWS Lambda中解析webhook的帮助器函数需要一个json。

更改网络钩正常工作updated GitHub WebHook

© www.soinside.com 2019 - 2024. All rights reserved.