Getting CORS headers in Flask error 500

I have a Flask app configured this way

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 correct routes. However, if an exception is thrown, debug output is generated without CORS headers. This means I can't see the debug output in chrome. Can I fix this?

+3


source to share


1 answer


The problem is related to the debug mode setting. You can find out about this in this GitHub issue .

There are two ways to get around this. The easiest is to set the config option PROPAGATE_EXCEPTIONS

to False

, but that robs you of the stack trace pages in debug mode:



app.config['PROPAGATE_EXCEPTIONS'] = False

      

The second way is to write your own exception handler. I haven't tried this myself, but the source flask may give you directions.

+1


source







All Articles