Spaces:
Sleeping
Sleeping
Update main.py
Browse files102 unmodified lines1031041051061071081091101111121131141 unmodified line116117118119120121102 unmodified lines"limit": req.limit,}async with httpx.AsyncClient(timeout=TIMEOUT) as client:try:resp = await client.get(f"{SEARXNG_URL}/search", params=params)if resp.status_code != 200:logger.error("search_http_error", status=resp.status_code, query=q)raise HTTPException(502, "Поисковый сервис вернул ошибку")data = resp.json()except httpx.RequestError as e:logger.error("search_request_error", error=str(e), query=q)1 unmodified lineexcept ValueError:logger.error("search_non_json_response", query=q)raise HTTPException(502, "Некорректный ответ от поискового сервиса")except Exception as e:logger.error("search_unexpected_error", error=str(e), query=q)raise HTTPException(502, "Внутренняя ошибка поиска")102 unmodified lines1031041051061071081091101111121131141151161171181191201211221231241251261271 unmodified line129130131132133134135136102 unmodified lines"limit": req.limit,}# Ждём готовности SearXNG (до 30 секунд)for _ in range(30):try:async with httpx.AsyncClient(timeout=2.0) as test_client:test_resp = await test_client.get(f"{SEARXNG_URL}/healthz")if test_resp.status_code == 200:breakexcept:await asyncio.sleep(1)async with httpx.AsyncClient(timeout=TIMEOUT) as client:try:resp = await client.get(f"{SEARXNG_URL}/search", params=params)if resp.status_code == 404:logger.error("searxng_404", url=f"{SEARXNG_URL}/search", query=q)raise HTTPException(502, "Поисковый сервис не настроен (404)")if resp.status_code != 200:logger.error("search_http_error", status=resp.status_code, query=q)raise HTTPException(502, f"Поисковый сервис вернул ошибку {resp.status_code}")data = resp.json()except httpx.RequestError as e:logger.error("search_request_error", error=str(e), query=q)1 unmodified lineexcept ValueError:logger.error("search_non_json_response", query=q)raise HTTPException(502, "Некорректный ответ от поискового сервиса")except HTTPException:raiseexcept Exception as e:logger.error("search_unexpected_error", error=str(e), query=q)raise HTTPException(502, "Внутренняя ошибка поиска")
main.py+16-1