Failing to sync collection from Python script

I have a few python scripts for manipulating my decks which work great but I’d also like to be able to sync my collection without starting up the desktop app. I wrote a simple little funciton like this which gets the SyncAuth object and passes it to Collection.sync_collection, like so:

def sync_deck():
    auth = col.sync_login("username", "password")

However I get this exception:
…\env\lib\site-packages\", line 131, in _run_command
raise backend_exception_to_pylib(err)
anki.errors.DBError: DbError { info: “SqliteFailure(Error { code: Unknown, extended_code: 1 }, Some(“cannot start a transaction within a transaction”))”, kind: Other }

Any ideas why this is the case, have I missed a key enabling step?

Thank you,


I have solved this one myself.

The error seemed to be something to do with transactions and sure enough the above modification to the code fixed it.


You should also save and re-use the auth info instead of authenticating each time, as you may end up being inadvertently blocked by doing it too frequently.


thanks have implemented this as well