import sqlite3 c = sqlite3.connect("/app/data/stripe_webhook.sqlite") r = c.execute( "SELECT customer_email FROM licenses WHERE lower(trim(coalesce(status,'')))='active' " "AND trim(coalesce(practice_id,''))!='' LIMIT 1" ).fetchone() print(r[0] if r and r[0] else "")