pythonjsongithubaws-lambdagit-webhooks

Parsing a GitHub WebHook payload results in Json decode error


While parsing the payload received from a GitHub WebHook, facing this issue JSONDecodeError: Expecting value: line 1 column 1 (char 0)

payload looks like

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

Error stack trace

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)


Solution

  • After closely looking at the GitHub WebHook configuration and the payload output, there was a mismatch.

    GitHub WebHook was configured to pass request in content type : x-www-form-urlencoded. Further the payload print also looks like urlencoded and not json.

    But my helper function in AWS Lambda that parses the webhook was expecting a json.

    Changing the webhook worked updated GitHub WebHook