{"record":{"id":"ae18427a977652ec","repo":"datawhalechina/hello-agents","slug":"poi-str-e-ae1842","errorCode":null,"errorMessage":"搜索POI失败: {str(e)}","messagePattern":"搜索POI失败: (.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"code/chapter13/helloagents-trip-planner/backend/app/api/routes/poi.py","lineNumber":83,"sourceCode":"        keywords: 搜索关键词\n        city: 城市名称\n\n    Returns:\n        搜索结果\n    \"\"\"\n    try:\n        amap_service = get_amap_service()\n        result = amap_service.search_poi(keywords, city)\n\n        return {\n            \"success\": True,\n            \"message\": \"搜索成功\",\n            \"data\": result\n        }\n\n    except Exception as e:\n        print(f\"❌ 搜索POI失败: {str(e)}\")\n        raise HTTPException(\n            status_code=500,\n            detail=f\"搜索POI失败: {str(e)}\"\n        )\n\n\n@router.get(\n    \"/photo\",\n    summary=\"获取景点图片\",\n    description=\"根据景点名称从Unsplash获取图片\"\n)\nasync def get_attraction_photo(name: str):\n    \"\"\"\n    获取景点图片\n\n    Args:\n        name: 景点名称\n\n    Returns:","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/datawhalechina/hello-agents/blob/606a07d341a47be773fab7f4b71177f53f96b2c3/code/chapter13/helloagents-trip-planner/backend/app/api/routes/poi.py#L65-L101","documentation":"HTTPException(500) raised by GET /poi/search (chapter13 poi routes) when amap_service.search_poi(keywords, city) throws. Identical failure surface to the /map/poi/search route (both call the Amap service) but on the dedicated poi router; the cause message is preserved in detail.","triggerScenarios":"Missing/invalid AMAP_API_KEY; amap-mcp-server subprocess not startable on the host; empty keywords param; network egress blocked from the backend container.","commonSituations":"Env var not loaded in the deployed environment; uvx missing in Docker image; Amap quota exhausted; calling before service initialization completed.","solutions":["Read the '❌ 搜索POI失败' log and embedded detail for the true cause","Validate AMAP_API_KEY in .env and test the Amap place/text API directly","Confirm uvx + network availability on the host/container","Default city='北京' applies if omitted — pass an explicit supported city to avoid upstream errors"],"exampleFix":"# before\nr = requests.get(f'{BASE}/poi/search', params={'keywords': ''})  # empty -> 500\n\n# after\nassert keywords.strip(), 'keywords required'\nr = requests.get(f'{BASE}/poi/search', params={'keywords': keywords, 'city': city})\nr.raise_for_status()","handlingStrategy":"try-catch","validationCode":"assert keywords and keywords.strip(), 'keywords must be non-empty'\nassert city.strip(), 'city must be non-empty'\n# service-level precheck\nimport requests\nassert requests.get(f'{BASE}/map/health').status_code == 200, 'map service down'","typeGuard":null,"tryCatchPattern":"try:\n    r = requests.get(f'{BASE}/poi/search', params={'keywords': kw, 'city': city}, timeout=15)\n    r.raise_for_status()\nexcept requests.HTTPError as e:\n    detail = e.response.json().get('detail', '')\n    if 'KEY' in detail.upper():\n        raise SystemExit('Amap key problem — fix backend .env')\n    raise","preventionTips":["Never send empty keywords/city","Share one health precheck across all map/poi calls per session","Log the detail field client-side; it distinguishes key vs network vs quota failures"],"tags":["fastapi","http-500","amap","poi","search"],"backgroundTag":null,"analyzedSha":"606a07d341a47be773fab7f4b71177f53f96b2c3","analyzedAt":"2026-08-14T22:57:27.446Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}