I have some troubles with a Flask application I’m trying to run.
When I make a curl call to this server (the url points to the server’s localhost, e.g. http://localhost:5000/[FLASK_ROUTE]), the Flask app is instanced by a script (main.py), which looks like this:
from flask import Flask
from routes_en import spacy_en_api
app = Flask(__name__)
app.register_blueprint(spacy_en_api)
if __name__ == '__main__':
app.run()
which then routes to another file (routes_en.py), which looks like this:
from flask import Blueprint
from flask import request
from flask import jsonify
import spacy
nlp = spacy.load('en')
spacy_en_api = Blueprint('spacy_en_api', __name__)
@spacy_en_api.route("/[MY_CUSTOM_ROUTE]", methods=['POST'])
def [MY_CUSTOM_ROUTE]():
data["output"] = "test - it works"
return jsonify(data)
@spacy_en_api.route("/en_parse_text", methods=['POST'])
def en_parse_text():
# code here
where “en_parse_text” is code written by someone before me. This part of the script works fine when called (http://localhost:5000/en_parse_text returns the expected output).
However, when I insert a new route (MY_CUSTOM_ROUTE), I get no output. When I check the logs, it reads “127.0.0.1 – – [DATE] “POST /MY_CUSTOM_ROUTE HTTP/1.1 404 -“.
What’s more: if I write new code in an existing route (e.g. I replace “# code here” with “print(“testing”)”, the curl call returns not my code, but the code that I replaced/commented out.
Also might be important: Flask version is 1.1.1 / Python 3.7.3 / Werkzueg 0.15.5
What could cause the app to not recognize my new route? Thanks in advance for the help.
sharp_blur is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.