# 坏请求键错误：请求无法理解

- **ID:** `python/flask-request-data-missing`
- **领域:** python
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

访问请求中不存在的表单或查询参数且未提供默认值，导致Flask抛出BadRequestKeyError。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.x | active | — | — |

## 解决方案

1. **** (100% 成功率)
   ```
   Use `request.form.get('key')` or `request.args.get('key')` which returns None if missing.
   ```
2. **** (95% 成功率)
   ```
   Provide a default value: `request.form.get('key', 'default')`.
   ```

## 无效尝试

- **** — Using `request.form['key']` raises the error if key is missing; using `.get()` is a better approach. (90% 失败率)
- **** — Catching the exception and returning a generic error doesn't provide useful feedback to the client. (80% 失败率)
