python
type_error
ai_generated
true
类型错误:__call__() 接受 1 个位置参数,但给出了 2 个
TypeError: __call__() takes 1 positional argument but 2 were given
ID: python/starlette-middleware-error
80%修复率
84%置信度
0证据数
2025-09-15首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.x | active | — | — | — |
根因分析
中间件类未正确实现 __call__ 方法。
English
中间件类未正确实现 __call__ 方法。
解决方案
-
95% 成功率
class MyMiddleware:\n def __init__(self, app):\n self.app = app\n async def __call__(self, scope, receive, send):\n await self.app(scope, receive, send)
-
85% 成功率
async def simple_middleware(request, call_next):\n response = await call_next(request)\n return response
无效尝试
常见但无效的做法:
-
70% 失败
签名不匹配。
-
90% 失败
导致中间件无法工作。