[Python] API Connection doesnt recognize correct function

Discussão em 'Python' iniciado por Stack, Junho 6, 2025.

  1. Stack

    Stack Membro Participativo

    I have this Code just to try if my api works and to implement a useful function later:

    from flask import Flask, jsonify
    from flask_cors import CORS
    import mysql.connector
    import pandas as pd
    import io
    import json

    app = Flask(__name__)
    CORS(app)




    @app.route('/contacts')
    def index():
    return jsonify({'message': 'API läuft', 'route': '/contacts'})

    db = mysql.connector.connect(
    host = "localhost",
    user = "root",
    password = "******",
    database = "******"
    )
    if __name__ == "__main__":
    app.run(Debug = True)


    in the console i get the path to the current api and direct to /contacts to call on the api and get: TypeError

    TypeError: The view function for 'index' did not return a valid response. The function either returned None or ended without a return statement.

    i already tried to implement it without jsonify but same result. also tried it without the database connection incase it fails. Other posts suggested a function that return none but i dont have that. this is the current entire code

    Continue reading...

Compartilhe esta Página