{
  "id": "python/starlette-memory-error-upload",
  "signature": "MemoryError: Unable to allocate array with shape (100000000,) and data type float64",
  "signature_zh": "内存错误：无法分配形状为 (100000000,) 且数据类型为 float64 的数组",
  "regex": "MemoryError:\\ Unable\\ to\\ allocate\\ array\\ with\\ shape\\ \\(100000000,\\)\\ and\\ data\\ type\\ float64",
  "domain": "python",
  "category": "system_error",
  "subcategory": null,
  "root_cause": "Attempting to read a large file upload into memory all at once in a Starlette/FastAPI endpoint.",
  "root_cause_type": "generic",
  "root_cause_zh": "在 Starlette/FastAPI 端点中尝试一次性将大文件上传读入内存。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "These don't affect Python's heap allocation for large numpy arrays; physical RAM is exhausted.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "This loads the whole file into a bytes object, still causing memory pressure.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.85,
      "how": "Stream the file using UploadFile.read(chunk_size) in a loop and process chunks: while chunk := await file.read(1024*1024): process(chunk)",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.8,
      "how": "Use a temporary file on disk: with tempfile.NamedTemporaryFile(delete=False) as tmp: shutil.copyfileobj(file.file, tmp)",
      "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": "partial",
  "first_seen": "2024-05-11",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}