pythonflask

HTTP 404 on flask server when just returning provided parameter


I have a simple flask-app like this:

from flask import Flask

app = Flask(__name__)

@app.route("/getExposeIds/<cookie>")
def getExposeIds(cookie):
    
    return cookie

I'm running the app as follows:

flask --app myscript run

When I call that url in my brower using localhost:5000/getExposeIds/whatever everything works as expected and my service returns "whatever". However when I provide an (url-encoded) value like this one

aws-waf-token%3D48eba622-3632-46b6-ae55-9f0637582425%3ACQoAmXuXthkqAQAA%3AhoU4a212KQ5MCAFIDflGc6vLRzYVJJAyzQS4mY%2BinAkE00MuRpE5YMc9ayD3wiUe4WEsggWn8fGH4holoE6w8khw3YTuOXQ0mUJcwmTyBAeswFnUzqPa1XvrK1DCsAazLqsI8o9RYwTDQ%2BflHbw12xJ9yfb0E7Vx6Y6d07ATWI1FbJDGb%2BzkbuY8WCCiM%2Bi6KA0%2B9u0jD59M%2FYwoPOdM2g%3D%3D

I get an HTTP 404.


Solution

  • I believe the issue is as Michael Logothetis suggested. You are having issues because of the %2F. Flask is automatically decoding the parameter you're passing as a string by default (see https://flask.palletsprojects.com/en/stable/api/#url-route-registrations). You can specify a converter to accommodate for the possibility that your string will include a / by using /getExposeIds/<path:cookie> as your endpoint.