Resolving a non-functional redirect in Flask

Posted: Thursday 2 October 2014

So I recently encountered an interesting issue in Flask, and one that's quite simple to solve, looking at it now.

But Google Chrome returned a "Failed to load response data" message, when preforming a 301 redirect in Flask...

And apparently, only Provisional Headers were shown in Google Chrome, presumably meaning that the response malformed somewhere...

So the relevant code fragment used was a basic redirect in Flask: return redirect(request.headers['Host']+cleanedpath)

Why I thought to be weird as the url address matches the result that was required explicitly.

Though. Apparently, adding the hosts caused the entire request to malform, for whatever reason I will still not know.

So to fix the redirection in Flask if you've used a similar code fragment to the one above, just get rid of the request.headers['Host'] part so that you end up with something looking like: return redirect(cleanedpath).

Flask apparently won't redirect to the full url as the "redirect" function only takes paths.