{
  "id": "python/flask-jsonify-nan-error",
  "signature": "ValueError: Out of range float values are not JSON compliant",
  "signature_zh": "值错误：超出范围的浮点值不符合 JSON 规范",
  "regex": "ValueError:\\ Out\\ of\\ range\\ float\\ values\\ are\\ not\\ JSON\\ compliant",
  "domain": "python",
  "category": "data_error",
  "subcategory": null,
  "root_cause": "Flask 的 jsonify 无法处理 NaN 或 Infinity 浮点值。",
  "root_cause_type": "generic",
  "root_cause_zh": "Flask 的 jsonify 无法处理 NaN 或 Infinity 浮点值。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "JSON 标准不支持 Infinity。",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "客户端可能期望数值类型。",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "导致响应失败。",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "使用 math.isnan() 检查并替换为 None",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.8,
      "how": "配置 Flask 的 JSONProvider 允许 NaN，如 app.json.ensure_ascii = False",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "使用自定义 JSONEncoder 覆盖 default 方法",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.82,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2025-03-01",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}