You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 ...
The text was updated successfully, but these errors were encountered:
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
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
results in a
NOT OK: 415
statusThis 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 atry-except
statement: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 ...
The text was updated successfully, but these errors were encountered: