【问题标题】:Flask REST: TypeError: get() got an unexpected keyword argumentFlask REST: TypeError: get() got an unexpected keyword argument
【发布时间】:2021-06-03 12:51:34
【问题描述】:

嘿,我遇到了 Flask REST 端点的问题,它有一个可选参数。我在其他地方有完全相同的代码并且它可以工作,所以我在这里不知所措。

这是资源的代码:

@api.route(
    "/get_sick_calls/<string:start_date>/<string:end_date>/",
    "/get_sick_calls/<string:start_date>/<string:end_date>/<int:num_sick_calls>",
    defaults={'num_sick_calls': 3}
)
class GetSickCalls(Resource):

    ##method_decorators = [authenticate]

    @api.doc(
        responses={
            201: "OK",
            401: INVALID_DATE_MSG,
            402: "DATE_RANGE_INVALID",
        },
        params={
            "start_date": "ISO 8601 Date String: YYYY-mm-dd",
            "end_date": "ISO 8601 Date String: YYYY-mm-dd",
            "num_sick_calls": "Minium number of sick calls, default is 3",
        },
    )
    # @authenticate
    def get(self, start_date: str, end_date: str, num_sick_calls: int):
        # validate date inputs

每当我访问任一路由时,都会收到 500 内部服务器错误:TypeError: get() got an unexpected keyword argument 'num_sick_calls'

我尝试将 num_sick_calls 更改为 *args, **kwargs 但同样的事情。有什么建议吗?

【问题讨论】:

    标签: python rest flask openshift


    【解决方案1】:

    抱歉,该代码没有任何问题,我没有意识到下面还有另一个 get 方法覆盖了第一个(不知道为什么我批准了那个 PR...)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-02-21
      • 1970-01-01
      • 2021-01-19
      • 1970-01-01
      • 2020-05-01
      • 2022-01-12
      • 2015-09-23
      相关资源
      最近更新 更多