# werkzeug.exceptions.BadRequestKeyError: 400 Bad Request: KeyError: 'file'

- **ID:** `python/flask-request-files-error`
- **Domain:** python
- **Category:** data_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

The request does not contain the expected file field, likely because the form data is missing or the field name is incorrect.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.x | active | — | — |

## Workarounds

1. **** (95% success)
   ```
   Check if 'file' in request.files before accessing: if 'file' not in request.files:\n    return 'No file part', 400
   ```
2. **** (90% success)
   ```
   Ensure the HTML form has enctype='multipart/form-data' and the input name matches.
   ```

## Dead Ends

- **** — Using request.files.get('file') returns None but doesn't raise an error, leading to AttributeError later. (70% fail)
- **** — Catching BadRequestKeyError and ignoring it results in silent failures. (50% fail)
