Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Events API example webhook no longer works with Flask 3.0 #4463

Open
kohlschuetter opened this issue Jan 29, 2025 · 0 comments
Open

Events API example webhook no longer works with Flask 3.0 #4463

kohlschuetter opened this issue Jan 29, 2025 · 0 comments
Assignees
Milestone

Comments

@kohlschuetter
Copy link

Tested with py3-flask-3.0.3-r0 from Alpine Linux:

Running the Events API example webhook (see https://docs.gluster.org/en/main/Administrator-Guide/Events-APIs/#webhooks) with

gluster-eventsapi webhook-test http://192.168.122.188:9000/listen

results in a NOT OK: 415 status

This is due to flask now failing with a 415 error ("Unsupported media type"), due to "request.json" throwing an exception instead of simply returning None.

Fix: wrap request.json in a try-except statement:

from flask import Flask, request

app = Flask(__name__)

@app.route("/listen", methods=["POST"])
def events_listener():
    try:
        gluster_event = request.json
    except:
        gluster_event = None

    if gluster_event is None:
        # No event to process, may be test call
        return "OK"

    # Process gluster_event
    # {
    #  "nodeid": NODEID,
    #  "ts": EVENT_TIMESTAMP,
    #  "event": EVENT_TYPE,
    #  "message": EVENT_DATA
    # }
    print (gluster_event)
    return "OK"

app.run(host="0.0.0.0", port=9000)

Note that regular events are still handled OK by the original script. Maybe the webhook-test code should just specify a well-formed event JSON object, with a specific event type, e.g., WEBHOOK_TEST. This would also help simplifying real servers ...

@kohlschuetter kohlschuetter changed the title Events API example webhook no longer works with 3.0 Events API example webhook no longer works with Flask 3.0 Jan 29, 2025
@sanjurakonde sanjurakonde added this to the Gluster 11.3 milestone Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants