{"record":{"id":"f3b771b90563979d","repo":"datawhalechina/hello-agents","slug":"str-e-f3b771","errorCode":null,"errorMessage":"天气查询失败: {str(e)}","messagePattern":"天气查询失败: (.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"code/chapter13/helloagents-trip-planner/backend/app/api/routes/map.py","lineNumber":93,"sourceCode":"    Returns:\n        天气信息\n    \"\"\"\n    try:\n        # 获取服务实例\n        service = get_amap_service()\n        \n        # 查询天气\n        weather_info = service.get_weather(city)\n        \n        return WeatherResponse(\n            success=True,\n            message=\"天气查询成功\",\n            data=weather_info\n        )\n        \n    except Exception as e:\n        print(f\"❌ 天气查询失败: {str(e)}\")\n        raise HTTPException(\n            status_code=500,\n            detail=f\"天气查询失败: {str(e)}\"\n        )\n\n\n@router.post(\n    \"/route\",\n    response_model=RouteResponse,\n    summary=\"规划路线\",\n    description=\"规划两点之间的路线\"\n)\nasync def plan_route(request: RouteRequest):\n    \"\"\"\n    规划路线\n    \n    Args:\n        request: 路线规划请求\n        ","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/datawhalechina/hello-agents/blob/606a07d341a47be773fab7f4b71177f53f96b2c3/code/chapter13/helloagents-trip-planner/backend/app/api/routes/map.py#L75-L111","documentation":"HTTPException(500) raised by GET /map/weather in the chapter13 backend when service.get_weather(city) throws. Like the other map routes it wraps any exception from the Amap MCP tool chain (config, subprocess, network, upstream API) into a 500 with the cause message preserved.","triggerScenarios":"weather MCP sub-tool missing because the amap server did not expand tools; invalid/missing AMAP_API_KEY; unsupported city name causing an upstream error surfaced as an exception; uvx subprocess failure on the host.","commonSituations":"Same environmental causes as the other /map routes: unset .env, missing uvx, quota-exhausted Amap key, or first-call timeout before the MCP server is warm.","solutions":["Check the server console for the '❌ 天气查询失败' line with the underlying message","Validate AMAP_API_KEY and that other map endpoints (e.g. /map/poi/search) work — isolates weather-specific vs service-wide failure","Test the Amap weather API directly with curl to rule out key/quota issues","Ensure uvx and network access exist on the backend host"],"exampleFix":"# before\nweather = requests.get(f'{BASE}/map/weather', params={'city': '北京'}).json()\n\n# after\nr = requests.get(f'{BASE}/map/weather', params={'city': '北京'})\nif r.status_code >= 500:\n    print('Map service error detail:', r.json().get('detail'))\nelse:\n    weather = r.json()","handlingStrategy":"try-catch","validationCode":"import requests\n\nif requests.get(f'{BASE}/map/health').status_code != 200:\n    raise SystemExit('Map service unhealthy')\n# pass a mainstream city name to avoid upstream geocode errors\nassert city.strip(), 'city required'","typeGuard":null,"tryCatchPattern":"try:\n    w = requests.get(f'{BASE}/map/weather', params={'city': city}, timeout=15)\n    w.raise_for_status()\nexcept requests.HTTPError as e:\n    detail = e.response.json().get('detail')\n    if 'APIKEY' in str(detail) or 'USERKEY' in str(detail).upper():\n        alert_ops('Amap key invalid/expired')\n    raise","preventionTips":["Health-check the map service at startup, not per request","Monitor for Amap quota errors in the detail messages and alert on them","Set client timeouts — upstream hangs otherwise propagate as opaque 500s"],"tags":["fastapi","http-500","amap","weather"],"backgroundTag":null,"analyzedSha":"606a07d341a47be773fab7f4b71177f53f96b2c3","analyzedAt":"2026-08-14T22:57:27.446Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}