import json from urllib import request data = json.dumps({ "frame_id": 26, # Need a valid frame_id! Let's get one from the db "engine": "sam3", "threshold": 0.35, "iou_threshold": 0.8, "min_box_frac": 0.0, "target_class_names": ["sack"] }).encode('utf-8') req = request.Request('http://localhost:8000/api/batches/5/preview', data=data, headers={'Content-Type': 'application/json'}) try: with request.urlopen(req) as response: print(response.read().decode('utf-8')) except Exception as e: print("Error:", getattr(e, 'read', lambda: str(e))())