Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting CORS headers in a Flask 500 error

Tags:

flask-cors

I've got a Flask app set up like this

from flask import Flask
from flask.ext.cors import CORS

app = Flask( . . . )
app.debug = True

CORS(app, allow_headers='Content-Type')

CORS works correctly for routes that complete properly. However, if an exception is raised, the debug output is generated without CORS headers. This means I cannot see the debug output in chrome. Can I fix this?

like image 217
Justin Dearing Avatar asked Apr 23 '15 13:04

Justin Dearing


1 Answers

The issue has to do with setting debug mode. You can see the discussion about this in this GitHub issue.

There are two ways you could get around this. The easiest is to set the PROPAGATE_EXCEPTIONS configuration parameter to False, but this deprives you of the debug-mode stack trace page:

app.config['PROPAGATE_EXCEPTIONS'] = False

The second would be to write your own exception handler. I haven't tried this myself, but the flask source can give you guidance.

like image 164
buck Avatar answered Sep 21 '22 19:09

buck