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?