Issue
I have a very simple GET handler in flask that looks like this:
@app.route('/thing/<thing_id>', methods=['GET'])
def get_thing(thing_id):
"""Get thing"""
json_in = {
"id": thing_id
}
return jsonify(app.thing_service.on_get_thing(json_in))
which is very simple, and complies with all the documentation for Flask. It works locally. However, when I push it to the server, it fails with the message:
TypeError: get_thing() takes no keyword arguments
which sounds like get_thing
is being passed some extra argument, but only on the server. If I account for these mysterious extra arguments that should not exist, it works, but there appear to be no arguments:
@app.route('/thing/<thing_id>', methods=['GET'])
def get_thing(thing_id, *args, **kwargs):
"""Get thing"""
logger.info(f'args: {args}')
logger.info(f'kwargs: {kwargs}')
json_in = {
"id": thing_id
}
return jsonify(app.thing_service.on_get_thing(json_in))
produces args: ()
and kwargs: {}
in the logs. But with this in place, the endpoint works. What could be causing this to happen?
The full traceback for the error:
Traceback (most recent call last):
File ".../python3.7/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File ".../python3.7/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
TypeError: get_thing() takes no keyword arguments
Solution
The answer is found here: Flask url with only one parameter is not processed
My code is cythonized as part of the CICD process. The local code is not. In the call to cythonize
, the compiler directive always_allow_keywords
must be set to True
.
Answered By - Fadecomic
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.