python type_error ai_generated true

TypeError: 路径操作中的 'function' 对象不可调用

TypeError: 'function' object is not callable in path operation

ID: python/fastapi-typeerror-path-operation-not-callable

其他格式: JSON · Markdown 中文 · English
80%修复率
85%置信度
0证据数
2024-06-10首次发现

版本兼容性

版本状态引入弃用备注
3.x active

根因分析

装饰器使用时不带括号,例如 @app.get 而不是 @app.get()。

English

A decorator is used without parentheses, e.g., @app.get instead of @app.get().

generic

解决方案

  1. 95% 成功率 Use decorator with parentheses and path
    @app.get('/items')
    async def get_items():
        return []
  2. 90% 成功率 Check for missing parentheses in custom decorators
    def my_decorator(func):
        return func
    # Use: @my_decorator
    def my_func(): pass

无效尝试

常见但无效的做法:

  1. Adding parentheses but not passing path 60% 失败

    Still missing required argument.

  2. Using class-based view incorrectly 50% 失败

    May conflict with function-based approach.