Issue
I have this Python code:
@reports_api.route('/reports/xlsx/organisations/<int:organisation_id>/', methods=['GET'])
@reconnect_to_db
@check_permissions(request, employee_constraints={}, client_user_constraints={}, in_args=True)
def get_organisation_containers_report_xlsx(organisation_id, employee_id):
if request.method == 'GET':
recipient = request.args.get('recipient')
report_str_io = ExcelReportsManager.get_organisation_containers_report(organisation_id, employee_id, recipient == 'up')
return flask.jsonify(**report_str_io), 200
When i use route to this api, i've get error
TypeError: get_organisation_containers_report_xlsx() got multiple values for argument 'organisation_id'
There is the path, that leads to api:
http://localhost:5000/reports/xlsx/organisations/1/?employee_id=2
What I'm doing wrong?
Solution
Error was in function args. Need to use request.args.get('employee_id')
.
And code will be like this:
@reports_api.route('/reports/xlsx/organisations/<int:organisation_id>/', methods=['GET'])
@reconnect_to_db
@check_permissions(request, employee_constraints={}, client_user_constraints={}, in_args=True)
def get_organisation_containers_report_xlsx(organisation_id):
if request.method == 'GET':
recipient = request.args.get('recipient')
report_str_io = ExcelReportsManager.get_organisation_containers_report(organisation_id, request.args.get('employee_id'), recipient == 'up')
return flask.jsonify(**report_str_io), 200
It works when we sending args in path to api like this:
http://localhost:5000/reports/xlsx/organisations/1/?employee_id=2
Answered By - Ingwar
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.