[GNC] Python script can't read Gnucash files

John Haiducek jhaiduce at gmail.com
Sat Nov 30 13:55:58 EST 2024


Hi,

A Python script I've been using with Gnucash recently stopped working, and
is no longer able to read files that could be read previously with the same
script. The script can open Gnucash XML files, but it doesn't find the
accounts in them. The script uses the official Gnucash Python API. Both
Gnucash and the Python bindings were installed using the Fedora package
manager.

Here's the script:

```
from sys import argv
from gnucash import Session, SessionOpenMode

def account_from_path(top_account, account_path, original_path=None):
    if original_path==None: original_path = account_path
    account, account_path = account_path[0], account_path[1:]

    account = top_account.lookup_by_name(account)
    if account == None:
        raise Exception(
            "path " + ':'.join(original_path) + " could not be found")

    if len(account_path) > 0 :
        return account_from_path(account, account_path, original_path)
    else:
        return account

if __name__=='__main__':

    gnucash_file = argv[1]

    gnucash_session=Session(gnucash_file, SessionOpenMode.SESSION_READ_ONLY)

    root_account = gnucash_session.book.get_root_account()

    investments = account_from_path(root_account, ['Assets','Investments'])
```

I'm experiencing this with Gnucash 5.9 on Fedora 39, installed using the
Fedora repositories. I'm not sure how to tell whether this is a Gnucash
bug, or a packaging error on the Fedora side, or something else. Any
suggestions for diagnosing or troubleshooting this?

John


More information about the gnucash-user mailing list