error creating new gnucash file with python

Geert Janssens geert.gnucash at kobaltwit.be
Sun Nov 23 12:21:33 EST 2014


On Saturday 22 November 2014 22:51:33 Ulrich Möhrke wrote:
> Hello,
> 
> I try to create a new gnucash file with python as done within
> example new_book_with_opening_balances.py
> (http://svn.gnucash.org/docs/HEAD/new__book__with__opening__balances_8
> py_source.html).
> 
> I wrote a tiny script:
> -----------------------------------------
> from gnucash import Session
> from sys import argv
> new_book_session = Session(argv[1], is_new=True)
> -----------------------------------------
> 
> I get errors, if I call the script.
> First.	- Call the script as
> 	python new_session.py xml://xml_test.gnucash
> 	I get the error:
> 		Traceback (most recent call last):
> 		  File "new_session.py", line 3, in <module>
> 		    new_book_session = Session(argv[1], is_new=True)
> 		  File "/usr/lib/python2.7/dist-packages/gnucash/gnucash_core.py",
> line 105, in __init__ self.load()
> 		  File "/usr/lib/python2.7/dist-packages/gnucash/gnucash_core.py",
> line 144, in new_function
> self.raise_backend_errors(function.__name__)
> 		  File "/usr/lib/python2.7/dist-packages/gnucash/gnucash_core.py",
> line 122, in raise_backend_errors errors )
> 		gnucash.gnucash_core.GnuCashBackendException: call to new_function
> resulted in the following errors, ERR_FILEIO_UNKNOWN_FILE_TYPE
> Second.	- Call the script as
> 	python new_session.py sqlite3://sqlite_test.gnucash
> 		Traceback (most recent call last):
> 		  File "new_session.py", line 3, in <module>
> 		    new_book_session = Session(argv[1], is_new=True)
> 		  File "/usr/lib/python2.7/dist-packages/gnucash/gnucash_core.py",
> line 104, in __init__ self.begin(book_uri, ignore_lock, is_new,
> force_new)
> 		  File "/usr/lib/python2.7/dist-packages/gnucash/gnucash_core.py",
> line 144, in new_function
> self.raise_backend_errors(function.__name__)
> 		  File "/usr/lib/python2.7/dist-packages/gnucash/gnucash_core.py",
> line 122, in raise_backend_errors errors )
> 		gnucash.gnucash_core.GnuCashBackendException: call to begin 
resulted
> in the following errors, ERR_BACKEND_NO_HANDLER
> 
> I get the same errors calling the example script
> new_book_with_opening_balances.py.
> 
> How to get rid of these errors?
> 
> 
Hi Ulrich,

It looks like you have found a bug in the python bindings. It seems to have been introduced in 
an attempt to fix another bug [1].

I have reopened that bug for further investigation.

As a temporary workaround you could alter
/usr/lib/python2.7/dist-packages/gnucash/gnucash_core.py
In line 105 you will find:
self.load()
Replace this with
if not is_new:
    self.load()

Mind the indentation here: the 'i' from "if" should be right below the 's' from "self.begin" in the 
line before and self.load() should be indented even more. That will revert the part of the fix for 
bug 726891 that breaks creating new xml files via python. Note that with the change you can 
create new xml files but not sqlite3 files anymore.

Regards,

Geert

[1] https://bugzilla.gnome.org/show_bug.cgi?id=726891


More information about the gnucash-user mailing list