Flask function got multiple values for argument

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

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published