Fix sqlite3 cannot start a transaction within a transaction
Your script halts with sqlite3.OperationalError: cannot start a transaction within a transaction.
Why it happens
Python's sqlite3 driver opens an implicit transaction before write statements, so an explicit BEGIN fails when one is already open.
The fix
Either remove manual BEGIN statements and rely on default implicit handling with commit and rollback, or connect with autocommit True or isolation_level None and manage BEGIN yourself.
Takeaway
Pick one transaction style and use it consistently across your script.
Rather not debug this yourself?
We build and run automations so these errors are our problem, not yours. Tell us about your setup and we reply within 48 hours.