mirror of
https://github.com/lllin000/PaperForge.git
synced 2026-07-22 06:50:53 +00:00
fix: OCR diagnostic L2 probe uses POST instead of GET (PaddleOCR rejects GET)
This commit is contained in:
parent
a3270dc791
commit
13b3e142cc
2 changed files with 7 additions and 13 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue