1

I have a WebHook server and it is receiving a POST with the information in the Body. I need print this output but I dont get found the problem. (I tried to convert byte to string but does not work)

I used the next script but it does not work. https://pypi.org/project/Webhook-Listener/

SCRIPT: (The last print does not work)

Thank you in advance.

def parse_request(request, *args, **kwargs):
        logger.debug(
                "Received request:\n"
                + "Method: {}\n".format(request.method)
                + "Headers: {}\n".format(request.headers)
                + "Args (url path): {}\n".format(args)
                + "Keyword Args (url parameters): {}\n".format(kwargs)
                + "Body: {}\n".format(request.body.read(int(request.headers["Content-Length"])) if int(request.headers.get("Content-Length", 0)) > 0 else "")
        )
        body_raw = request.body.read((int(request.headers['Content-Length'])) if int(request.headers.get('Content-Length',0)) > 0 else "")
        body = json.loads(body_raw.decode('utf-8'))
        print(body)

Any suggestion?

  • Not completely sure but try `body = request.json()` – half of a glazier Mar 01 '21 at 14:16
  • A few things to try: 1- request.body might not have your info, instead it can be request.form or request.json. 2- Maybe the data is already in utf-8 so you don't need to decode it? 3- the format is not utf-8. – thethiny Mar 01 '21 at 14:19
  • This is console view: DEBUG :: __init__(73) :: Received POST request. args: (), kwargs: {} DEBUG :: __init__(82) :: Calling to process the request... DEBUG :: webhook_OT(82) :: Received request: Method: POST Headers: {'Content-Length': '2039', 'Remote-Addr': '172.16.1.3', 'Content-Type': 'application/json', 'Expect': '100-continue', 'Accept': '*/*', 'Host': '172.16.100.112'} Args (url path): () Keyword Args (url parameters): {} Body: b'{ "fortianalyzer_notification": { "type": "event alert", "adom": "root", "from": "FAZ-VMT", "timestamp": 1,.... – Andres Zapata Mar 01 '21 at 15:35

0 Answers0