@api.route('/my-resource/<id>', endpoint='my-resource')
@api.doc(params={'id': 'An ID'})
class MyResource(Resource):
@api.doc(responses={403: 'Not Authorized'})
def post(self, id):
api.abort(403)
如何避免这种pylint错误?任何人都可以有任何想法吗?
我尝试编写类似以下的构造函数:
@api.route('/my-resource/<id>', endpoint='my-resource')
@api.doc(params={'id': 'An ID'})
class MyResource(Resource):
def __init__(self):
self.counter = 0
@api.doc(responses={403: 'Not Authorized'})
def post(self, id):
api.abort(403)
但这不起作用。调用API时会引发内部服务器错误。 错误:
lib/python3.7/site-packages/flask/app.py", line 1813, in full_dispatch_request
rv = self.dispatch_request()
lib/python3.7/site-packages/flask/app.py", line 1799, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
lib/python3.7/site-packages/flask_restplus/api.py", line 319, in wrapper
resp = resource(*args, **kwargs)
/lib/python3.7/site-packages/flask/views.py", line 87, in view
self = view.view_class(*class_args, **class_kwargs)
TypeError: __init__() takes 1 positional argument but 2 were given
答案 0 :(得分:0)
可能还需要一个参数
简单修复
class MyResource(Resource):
def __init__(self):
self.counter = 0
@api.doc(responses={403: 'Not Authorized'})
def post(self, id):
api.abort(403)
到
class MyResource(Resource):
def __init__(self, _):
self.counter = 0
@api.doc(responses={403: 'Not Authorized'})
def post(self, id):
api.abort(403)
或
class MyResource(Resource):
@api.doc(responses={403: 'Not Authorized'})
def post(self, id):
api.abort(403)