Proper decoration in python of app route using a route variable for a flask api
Unanswered
Polar bear posted this in #help-forum
Polar bearOP
I'm building a Flask API that includes an unsubscribe endpoint. The endpoint needs to handle email addresses, which can contain special characters like '@' and '.'. Currently, I'm having issues with the route not being recognized properly in production, especially when the email contains these special characters.
Here's my current route decoration:
This works fine locally, but in production (hosted on Vercel), I'm getting 404 errors for this endpoint. All other endpoints without params are working great.
I've tried encoding the email on the frontend:
But I'm still encountering issues.
1. What's the proper way to decorate a Flask route to handle email addresses in the URL?
2. Do I need to handle the decoding of the email address differently in the function?
3. Are there any special considerations when deploying a Flask API with such routes to a serverless environment like Vercel?
Any insights or best practices for handling this scenario would be greatly appreciated. Thanks!
Here's my current route decoration:
@app.route('/api/unsubscribe/<string:email>', methods=['POST'])
def unsubscribe(email):
# function bodyThis works fine locally, but in production (hosted on Vercel), I'm getting 404 errors for this endpoint. All other endpoints without params are working great.
I've tried encoding the email on the frontend:
const encodedEmail = encodeURIComponent(email);But I'm still encountering issues.
1. What's the proper way to decorate a Flask route to handle email addresses in the URL?
2. Do I need to handle the decoding of the email address differently in the function?
3. Are there any special considerations when deploying a Flask API with such routes to a serverless environment like Vercel?
Any insights or best practices for handling this scenario would be greatly appreciated. Thanks!