Skip to content
Advertisement

ERR_TOO_MANY_REDIRECTS in a Flask application. Works in local but not in server

In local my Flask application works fine, and when I use /editing_buddy it redirects me correctly. The thing is, when I upload it to the server, it always gives me 404 Error.

If I try to use @app.route decorator, I get a TOO MANY REDIRECTS error. My server is hosted by Wikimedia in funpedia.toolforge.org if that helps. It’s a webservice with kubernetes backend.

My code is like this:

JavaScript

The apps for the “/” and “/editing_buddy” are Dash applications with the same url_base_pathname:

Buddy

JavaScript

Home

JavaScript

Locally, I start the server by running wsgi.py. Which contains the code:

JavaScript

In the server I simply run webservice restart, but I have a .ini file called app.ini with content:

JavaScript

And my folder structure is Folder Structure

PS: I’ve also tried hardcoding the redirects like flask.redirect("/editing_buddy/"). Even i’ve tried to hardcode the URL like flask.redirect("funpedia.toolforge.org/editing_buddy/") and either doesn’t find it or Too many redirects.

You can see my repo HERE

Advertisement

Answer

Now it works, why? I don’t have any clue. I did the next:

  1. I eliminated the app.ini from the directory of the app.py and put it on the root directory.
  2. In home.py, I renamed from app import app as application to just from app import app.
  3. Eliminated the unnecessary @app.route for the dash apps, they are not needed because you already have the url_base_pathname.

After doing some testing, I found that the solution is the step 2. By using from app import app in the home.py script.

HOWEVER, in the editing_buddy_app.py, I have it with from app import app as application AND IT WORKS

Definitely, I’m missing something here, but I’m unable to guess what.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement