From 13b3e142ccce222949c7b1cc018c98a2fc61bf4e Mon Sep 17 00:00:00 2001 From: Research Assistant Date: Mon, 27 Apr 2026 20:34:47 +0800 Subject: [PATCH] fix: OCR diagnostic L2 probe uses POST instead of GET (PaddleOCR rejects GET) --- paperforge/ocr_diagnostics.py | 12 +++--------- tests/test_ocr_doctor.py | 8 ++++---- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/paperforge/ocr_diagnostics.py b/paperforge/ocr_diagnostics.py index 2824681e..313f3989 100644 --- a/paperforge/ocr_diagnostics.py +++ b/paperforge/ocr_diagnostics.py @@ -36,15 +36,16 @@ def ocr_doctor(config: dict[str, str] | None, live: bool = False) -> dict: "fix": "Set PADDLEOCR_API_TOKEN in .env or environment variables and re-run `paperforge ocr --diagnose`", } - # L2 — URL reachability + # L2 — URL reachability (use POST since most endpoints reject GET) job_url = os.environ.get( "PADDLEOCR_JOB_URL", "https://paddleocr.aistudio-app.com/api/v2/ocr/jobs", ).strip() try: - resp = requests.get( + resp = requests.post( job_url, headers={"Authorization": f"bearer {token}"}, + json={"model": os.environ.get("PADDLEOCR_MODEL", "PaddleOCR-VL-1.5")}, timeout=30, ) if resp.status_code == 401: @@ -62,13 +63,6 @@ def ocr_doctor(config: dict[str, str] | None, live: bool = False) -> dict: "fix": "OCR provider is experiencing issues. Retry later with `paperforge ocr --diagnose`", } if resp.status_code != 200: - if resp.status_code == 405: - return { - "level": 2, - "passed": False, - "error": "URL returned 405 Method Not Allowed", - "fix": "PaddleOCR endpoint may require GET for probing but POST for OCR jobs. Check if your API endpoint supports both methods.", - } return { "level": 2, "passed": False, diff --git a/tests/test_ocr_doctor.py b/tests/test_ocr_doctor.py index a9e5f2f2..969ec441 100644 --- a/tests/test_ocr_doctor.py +++ b/tests/test_ocr_doctor.py @@ -25,13 +25,13 @@ def test_l1_missing_token(): # L2 — URL reachability # --------------------------------------------------------------------------- def test_l2_bad_url(): - """Mock GET returning 404 → level 2 failed.""" + """Mock POST returning 404 → level 2 failed.""" env = {"PADDLEOCR_API_TOKEN": "test-token"} mock_resp = MagicMock() mock_resp.status_code = 404 with patch.dict(os.environ, env, clear=True): - with patch("paperforge.ocr_diagnostics.requests.get", return_value=mock_resp): + with patch("paperforge.ocr_diagnostics.requests.post", return_value=mock_resp): result = ocr_doctor(config=None, live=False) assert result["level"] == 2 @@ -41,13 +41,13 @@ def test_l2_bad_url(): def test_l2_unauthorized(): - """Mock GET returning 401 → level 2 failed with auth message.""" + """Mock POST returning 401 → level 2 failed with auth message.""" env = {"PADDLEOCR_API_TOKEN": "bad-token"} mock_resp = MagicMock() mock_resp.status_code = 401 with patch.dict(os.environ, env, clear=True): - with patch("paperforge.ocr_diagnostics.requests.get", return_value=mock_resp): + with patch("paperforge.ocr_diagnostics.requests.post", return_value=mock_resp): result = ocr_doctor(config=None, live=False) assert result["level"] == 2