python type_error ai_generated true

TypeError: __call__() takes 1 positional argument but 2 were given

ID: python/starlette-middleware-error

Also available as: JSON · Markdown · 中文
80%Fix Rate
84%Confidence
0Evidence
2025-09-15First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.x active

Root Cause

中间件类未正确实现 __call__ 方法。

generic

中文

中间件类未正确实现 __call__ 方法。

Workarounds

  1. 95% success
    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)
  2. 85% success
    async def simple_middleware(request, call_next):\n    response = await call_next(request)\n    return response

Dead Ends

Common approaches that don't work:

  1. 70% fail

    签名不匹配。

  2. 90% fail

    导致中间件无法工作。