Skip to content

Issue from Sentry #121

@resolvd-ai

Description

@resolvd-ai

The error NameError: name 'jsonify' is not defined suggests that the jsonify function is not imported or defined in your code. To fix this issue, you need to import the jsonify function from the Flask module.

In your code, you can add the following import statement at the top of your file:

from flask import jsonify

Make sure to add this import statement before the get_users function.

Here is the updated code:

from flask import Flask, jsonify, request, logging

def get_users():
    age = request.args.get('age')
    if age:
        try:
            age = int(age)  # This can raise a ValueError
        except ValueError:
            logging.error("ERROR: Invalid age format provided.")
            return jsonify({"error": "Invalid age format"}), 400

    results = []
    for entry in data:
        if 'age' in entry:
            # Avoiding TypeError by ensuring both are integers for comparison
            if age and int(entry["age"]) == age:
                results.append(entry)
        elif not age:
            results.append(entry)

    return jsonify(results)


if __name__ == "__main__":
    app.run(debug=True)

By importing jsonify from the Flask module, you will be able to use it in the get_users function to convert the results into a JSON response.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions