Fix NameError in test-lpr endpoint (PLATERECOGNIZER_KEY scope)
PLATERECOGNIZER_KEY is defined in watcher.py, not main.py. Reference it via watcher.PLATERECOGNIZER_KEY inside the executor closure, and wrap _run() in a top-level try/except so exceptions always return JSON instead of a 500 HTML page. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
c43652d187
commit
d6f95131bc
+12
-4
@@ -325,17 +325,25 @@ async def test_lpr(event_id: str, frame_path: str = Form(""), bbox: str = Form("
|
|||||||
raise HTTPException(404, "Frame introuvable")
|
raise HTTPException(404, "Frame introuvable")
|
||||||
|
|
||||||
def _run():
|
def _run():
|
||||||
|
try:
|
||||||
|
return _run_inner()
|
||||||
|
except Exception as e:
|
||||||
|
logging.exception("test-lpr unhandled error")
|
||||||
|
return {"error": str(e)}
|
||||||
|
|
||||||
|
def _run_inner():
|
||||||
frame = cv2.imread(frame_abs)
|
frame = cv2.imread(frame_abs)
|
||||||
if frame is None:
|
if frame is None:
|
||||||
return {"error": "Impossible de lire l'image"}
|
return {"error": "Impossible de lire l'image"}
|
||||||
|
|
||||||
result: dict = {"has_pr": bool(PLATERECOGNIZER_KEY)}
|
pr_key = watcher.PLATERECOGNIZER_KEY
|
||||||
|
result: dict = {"has_pr": bool(pr_key)}
|
||||||
|
|
||||||
if PLATERECOGNIZER_KEY:
|
if pr_key:
|
||||||
from lpr import call_platerecognizer
|
from lpr import call_platerecognizer
|
||||||
from watcher import _normalize_plate
|
p, c = call_platerecognizer(frame, pr_key)
|
||||||
p, c = call_platerecognizer(frame, PLATERECOGNIZER_KEY)
|
|
||||||
if p:
|
if p:
|
||||||
|
from watcher import _normalize_plate
|
||||||
result["platerecognizer"] = {
|
result["platerecognizer"] = {
|
||||||
"plate": _normalize_plate(p) or p,
|
"plate": _normalize_plate(p) or p,
|
||||||
"raw": p,
|
"raw": p,
|
||||||
|
|||||||
Reference in New Issue
Block a user