Skip to content

Instantly share code, notes, and snippets.

@OPVL
Created April 24, 2026 08:49
Show Gist options
  • Select an option

  • Save OPVL/32d3e6000fd08d921d36f38e226ac5f9 to your computer and use it in GitHub Desktop.

Select an option

Save OPVL/32d3e6000fd08d921d36f38e226ac5f9 to your computer and use it in GitHub Desktop.
webhook receiver
#!/usr/bin/env python3
"""
Simple Webhook Receiver
Run this script to receive and display webhook data
"""
from http.server import HTTPServer, BaseHTTPRequestHandler
import json
import threading
import time
class WebhookReceiver(BaseHTTPRequestHandler):
def do_POST(self):
content_length = int(self.headers['Content-Length'])
post_data = self.rfile.read(content_length)
try:
data = json.loads(post_data.decode('utf-8'))
print(f"\n{'='*50}")
print(f"WEBHOOK RECEIVED AT: {time.strftime('%Y-%m-%d %H:%M:%S')}")
print(f"PATH: {self.path}")
print(f"CONTENT TYPE: {self.headers.get('Content-Type', 'unknown')}")
print(f"REQUEST HEADERS: {dict(self.headers)}")
print(f"PAYLOAD DATA:")
print(json.dumps(data, indent=2))
print(f"{'='*50}\n")
except json.JSONDecodeError:
print(f"\n{'='*50}")
print(f"WEBHOOK RECEIVED AT: {time.strftime('%Y-%m-%d %H:%M:%S')}")
print(f"PATH: {self.path}")
print(f"CONTENT TYPE: {self.headers.get('Content-Type', 'unknown')}")
print("RAW DATA:")
print(post_data.decode('utf-8'))
print(f"{'='*50}\n")
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
self.wfile.write(b"Webhook received successfully!")
def run_server(port=8000):
server_address = ('0.0.0.0', port)
httpd = HTTPServer(server_address, WebhookReceiver)
print(f"Webhook receiver server starting on http://{server_address[0]}:{server_address[1]}")
print("This will receive any webhook data sent to this address")
print("Press Ctrl+C to stop the server")
print("="*60)
try:
httpd.serve_forever()
except KeyboardInterrupt:
print("\nServer stopped.")
if __name__ == '__main__':
run_server()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment