Flask route to pull data from database for getJSON to process
I don't really get the purpose of the get_db function. Why not simply initialize the database at the very beginning like so:

db = connect_db()


And then use db in failed_access directly. It seems you wanted to do lazy initialization, but is it really worth it? Sooner or later, the database will be used anyway. Initializing upfront is straightforward, simple, and less error prone.