iflytek/astron-agent · error · HTTPException
Task creation failed
Error message
Task creation failed: {e.response.text} What it means
create_task converts httpx.HTTPStatusError (non-2xx response from the Xiaowu API) into HTTPException carrying the upstream status code and response text. It means the HTTP request itself failed with a non-success status.
Solutions
- Check e.response.text/status_code logged to identify the concrete HTTP failure
- Verify the task-create URL env var points at the correct endpoint
- Refresh/validate the access token used in the Authorization header
- Confirm network/gateway path to the RPA service is healthy
Example fix
// before
raise HTTPException(status_code=e.response.status_code, detail=f"Task creation failed: {e.response.text}") from e
// after
# keep mapping but truncate huge bodies and preserve cause
raise HTTPException(status_code=e.response.status_code, detail=f"Task creation failed: {e.response.text[:500]}") from e Defensive patterns
Strategy: try-catch
Validate before calling
if not is_valid_url(task_create_url):
raise InvalidConfigException(f"Invalid task create URL: {task_create_url}")
# also verify token non-empty before the call
assert access_token, "access token missing" Try / catch
try:
task_id = await create_task(payload)
except HTTPException as e:
if e.status_code in (429, 502, 503, 504):
schedule_retry(backoff=True)
elif e.status_code == 401:
refresh_token_and_retry()
else:
raise Prevention
- Validate the create-URL env var at startup
- Rotate/refresh Bearer tokens before expiry
- Set explicit httpx timeouts
- Monitor upstream 5xx rates
When it happens
Trigger: httpx.AsyncClient.post(...).raise_for_status() raises because the RPA API returned 4xx/5xx (e.g. 401 unauthorized, 404 wrong URL, 502 gateway error).
Common situations: Misconfigured XIAOWU_RPA_TASK_CREATE_URL (wrong path/port), expired Bearer token causing 401, upstream 5xx during outage, gateway/proxy errors.
Understand the failure class
Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.
Related errors
AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12).
Data as JSON: /api/errors/31d5231566b0c578.
Report an issue: GitHub.
Appendix: source
Thrown at core/plugin/rpa/infra/xiaowu/tasks.py:81
if code != "0000" or not data:
logger.error(f"Task creation failed: {msg}")
raise HTTPException(
status_code=500, detail=f"Task creation failed: {msg}"
)
task_id = data.get("executionId", None)
if not task_id:
logger.error("Task creation failed: No task ID returned")
raise HTTPException(
status_code=500,
detail=f"Task creation failed: No task ID returned: {response_data}",
)
return task_id
except httpx.HTTPStatusError as e:
logger.error(f"Task creation failed: {e.response.text}")
raise HTTPException(
status_code=e.response.status_code,
detail=f"Task creation failed: {e.response.text}",
) from e
except Exception as e:
logger.error(f"Task creation failed: {e}")
raise HTTPException(
status_code=500, detail=f"Task creation failed: {e}"
) from e
# Query task status
async def query_task_status(
access_token: str, task_id: str
) -> Tuple[int, str, dict] | None:
"""
Query task status.
- If task is completed, return task result.
- If task is not completed, return None.View on GitHub (pinned to 5e758547a8)