MoritzR / fints2ledger

A tool for downloading transactions from FinTS banking APIs and sorting them into a ledger journal
MIT License
26 stars 8 forks source link

Could not find a matching account for SEPAAccount #4

Closed varac closed 4 years ago

varac commented 4 years ago

I am using fints2ledger 0.5.2 together with the PSD2 support PR branch (pip install git+https://github.com/raphaelm/python-fints.git@refs/pull/95/head), which gets me around the Dialog response: 9075 - Starke Kundenauthentifizierung notwendig. error described in https://github.com/MoritzR/fints2ledger/issues/3#issuecomment-581017740.

But now I get this:

You should register your program with the ZKA and pass your own product_id as a parameter.
Traceback (most recent call last):
  File "/home/varac/.config/fints2ledger/.direnv/python-venv-3.7.5/bin/fints2ledger", line 10, in <module>
    sys.exit(main())
  File "/home/varac/.config/fints2ledger/.direnv/python-venv-3.7.5/lib/python3.7/site-packages/fints2ledger/main.py", line 9, in main
    Fints2Csv(config).retrieveAndSave()
  File "/home/varac/.config/fints2ledger/.direnv/python-venv-3.7.5/lib/python3.7/site-packages/fints2ledger/fints2csv.py", line 24, in retrieveAndSave
    transaction), retriever.get_hbci_transactions(self.config["fints"]["start"], Date.today())))
  File "/home/varac/.config/fints2ledger/.direnv/python-venv-3.7.5/lib/python3.7/site-packages/fints2ledger/transaction_retriever.py", line 9, in get_hbci_transactions
    account = self.__find_matching_account(accounts, self.accountnumber)
  File "/home/varac/.config/fints2ledger/.direnv/python-venv-3.7.5/lib/python3.7/site-packages/fints2ledger/transaction_retriever.py", line 18, in __find_matching_account
    .format(missing_account=account, accounts=accounts))
Exception: Could not find a matching account for SEPAAccount(iban='DE05_BLZ__SPARKONTO_', bic='BIC', accountnumber='_SPARKONTO_', subaccount=None, blz='_BLZ_'). Possible accounts: [SEPAAccount(iban='DE72_BLZ__GIROKONTO1_', bic='BIC', accountnumber='_GIROKONTO1_', subaccount=None, blz='_BLZ_'), SEPAAccount(iban='DE18_BLZ__GIROKONTO2_', bic='BIC', accountnumber='_GIROKONTO2_', subaccount=None, blz='_BLZ_'), SEPAAccount(iban='DE55_BLZ__KREDITKARTE_', bic='BIC', accountnumber='_KREDITKARTE_', subaccount=None, blz='_BLZ_'), SEPAAccount(iban='DE05_BLZ__SPARKONTO_', bic='BIC', accountnumber='_SPARKONTO_', subaccount=None, blz='_BLZ_')]

my config file looks like this:

# https://github.com/MoritzR/fints2ledger#install
fints:
  # account: "_GIROKONTO1_"
  blz: "_BLZ_"
  account: "_VRKENNUNG_"
  password: "_PIN_"
  endpoint: "https://…/cgi-bin/hbciservlet"
ledger:
  prompts:
    - credit_account
    - debit_account
  autocomplete:
    accounts:
      - credit_account
      - debit_account
  defaults:
    debit_account: assets:bank:checking
  md5:
    - date
    - payee
    - purpose
    - amount
MoritzR commented 4 years ago

I fixed an issue where the Exception always shows the last account in the list as the one it searched for (v0.5.4). The program is actually looking for a SEPAAccount with an accountNumber matching the account from the config.yml, _VRKENNUNG_ in your case.

I am wondering if you could use the account number for the account you are looking for as account in your config.yml or if the program should use some other method of selecting an account from all available accounts.

Can you try to use _GIROKONTO1_ as account in your config.yml?

varac commented 4 years ago

Can you try to use GIROKONTO1 as account in your config.yml?

This is what happenes when I use my GIROKONTO1 IBAN as account nr:

❯ fints2ledger --ledger-file ~/.config/fints2ledger/test.ledger

You should register your program with the ZKA and pass your own product_id as a parameter.
Traceback (most recent call last):
  File "/home/varac/.config/fints2ledger/.direnv/python-venv-3.7.5/bin/fints2ledger", line 10, in <module>
    sys.exit(main())
  File "/home/varac/.config/fints2ledger/.direnv/python-venv-3.7.5/lib/python3.7/site-packages/fints2ledger/main.py", line 9, in main
    Fints2Csv(config).retrieveAndSave()
  File "/home/varac/.config/fints2ledger/.direnv/python-venv-3.7.5/lib/python3.7/site-packages/fints2ledger/fints2csv.py", line 24, in retrieveAndSave
    transaction), retriever.get_hbci_transactions(self.config["fints"]["start"], Date.today())))
  File "/home/varac/.config/fints2ledger/.direnv/python-venv-3.7.5/lib/python3.7/site-packages/fints2ledger/transaction_retriever.py", line 7, in get_hbci_transactions
    accounts = self.client.get_sepa_accounts()
  File "/home/varac/.config/fints2ledger/.direnv/python-venv-3.7.5/lib/python3.7/site-packages/fints/client.py", line 452, in get_sepa_accounts
    with self._get_dialog() as dialog:
  File "/home/varac/.config/fints2ledger/.direnv/python-venv-3.7.5/lib/python3.7/site-packages/fints/client.py", line 273, in _get_dialog
    self._ensure_system_id()
  File "/home/varac/.config/fints2ledger/.direnv/python-venv-3.7.5/lib/python3.7/site-packages/fints/client.py", line 1142, in _ensure_system_id
    HKSYN3(SynchronizationMode.NEW_SYSTEM_ID),
  File "/home/varac/.config/fints2ledger/.direnv/python-venv-3.7.5/lib/python3.7/site-packages/fints/dialog.py", line 85, in init
    retval = self.send(*segments, internal_send=True)
  File "/home/varac/.config/fints2ledger/.direnv/python-venv-3.7.5/lib/python3.7/site-packages/fints/dialog.py", line 156, in send
    self.client.process_response_message(self, response, internal_send=internal_send)
  File "/home/varac/.config/fints2ledger/.direnv/python-venv-3.7.5/lib/python3.7/site-packages/fints/client.py", line 230, in process_response_message
    self._process_response(dialog, None, response)
  File "/home/varac/.config/fints2ledger/.direnv/python-venv-3.7.5/lib/python3.7/site-packages/fints/client.py", line 1294, in _process_response
    raise FinTSClientPINError("Error during dialog initialization, PIN wrong?")
fints.exceptions.FinTSClientPINError: Error during dialog initialization, PIN wrong?
varac commented 4 years ago

I am wondering if you could use the account number for the account you are looking for as account in your config.yml or if the program should use some other method of selecting an account from all available accounts.

If it works and is documented well I don't care too much what is used as account number.

MoritzR commented 4 years ago

Try out the new version 0.5.5 and add a selectedAccount to your config.yml like this:

fints:
  blz: ...
  account: "_VRKENNUNG_"
  password: "_PIN_"
  endpoint: "https://…/cgi-bin/hbciservlet"
  selectedAccount: "_GIROKONTO1_"
varac commented 4 years ago

Try out the new version 0.5.5 and add a selectedAccount to your config.yml like this:

fints:
  blz: ...
  account: "_VRKENNUNG_"
  password: "_PIN_"
  endpoint: "https://…/cgi-bin/hbciservlet"
  selectedAccount: "_GIROKONTO1_"

I tried that with 0.5.5, but this gives me exactly the same error as the original issue description:

Exception: Could not find a matching account for SEPAAccount(iban='DE05_BLZ__SPARKONTO_', bic='BIC', accountnumber='_SPARKONTO_', subaccount=None, blz='_BLZ_'). Possible accounts: [SEPAAccount(iban='DE72_BLZ__GIROKONTO1_', bic='BIC', accountnumber='_GIROKONTO1_', subaccount=None, blz='_BLZ_'), SEPAAccount(iban='DE18_BLZ__GIROKONTO2_', bic='BIC', accountnumber='_GIROKONTO2_', subaccount=None, blz='_BLZ_'), SEPAAccount(iban='DE55_BLZ__KREDITKARTE_', bic='BIC', accountnumber='_KREDITKARTE_', subaccount=None, blz='_BLZ_'), SEPAAccount(iban='DE05_BLZ__SPARKONTO_', bic='BIC', accountnumber='_SPARKONTO_', subaccount=None, blz='_BLZ_')]
MoritzR commented 4 years ago

I tried that with 0.5.5, but this gives me exactly the same error as the original issue description

This is weird. If I use some invalid account number as selectedAccount I get the following error:

Exception: Could not find a matching account for account number '123456789'. Possible accounts: [SEPAAccount(iban= ...

It could be that you are still on an older version. Can you check that you have the 0.5.5 installed? (for example with pip show fints2ledger)

varac commented 4 years ago

I'm on 0.5.5:

❯ pip3 show fints2ledger

Name: fints2ledger
Version: 0.5.5
Summary: A tool for downloading transactions from FinTS banking APIs and sorting them into a ledger journal.
Home-page: https://github.com/MoritzR/fints2ledger
Author: Moritz Rumpf
Author-email: moritz.rumpf@gmail.com
License: MIT
Location: /home/varac/.config/fints2ledger/.direnv/python-venv-3.7.5/lib/python3.7/site-packages
Requires: mt-940, fints, pyyaml
Required-by: 

❯ fints2ledger --ledger-file ~/.config/fints2ledger/test.ledger 
You should register your program with the ZKA and pass your own product_id as a parameter.
Traceback (most recent call last):
  File "/home/varac/.config/fints2ledger/.direnv/python-venv-3.7.5/bin/fints2ledger", line 10, in <module>
    sys.exit(main())
  File "/home/varac/.config/fints2ledger/.direnv/python-venv-3.7.5/lib/python3.7/site-packages/fints2ledger/main.py", line 9, in main
    Fints2Csv(config).retrieveAndSave()
  File "/home/varac/.config/fints2ledger/.direnv/python-venv-3.7.5/lib/python3.7/site-packages/fints2ledger/fints2csv.py", line 24, in retrieveAndSave
    transaction), retriever.get_hbci_transactions(self.config["fints"]["start"], Date.today())))
  File "/home/varac/.config/fints2ledger/.direnv/python-venv-3.7.5/lib/python3.7/site-packages/fints2ledger/transaction_retriever.py", line 9, in get_hbci_transactions
    account = self.__find_matching_account(accounts, self.accountnumber)
  File "/home/varac/.config/fints2ledger/.direnv/python-venv-3.7.5/lib/python3.7/site-packages/fints2ledger/transaction_retriever.py", line 18, in __find_matching_account
    .format(missing_account=accountnumber, accounts=accounts))
Exception: Could not find a matching account for account number 'DE72_BLZ__GIROKONTO1_'. Possible accounts: [SEPAAccount(iban='DE72_BLZ__GIROKONTO1_', bic='BIC', accountnumber='_GIROKONTO1_', subaccount=None, blz='_BLZ_'), SEPAAccount(iban='DE18_BLZ__GIROKONTO2_', bic='BIC', accountnumber='_GIROKONTO2_', subaccount=None, blz='_BLZ_'), SEPAAccount(iban='DE55_BLZ__KREDITKARTE_', bic='BIC', accountnumber='_KREDITKARTE_', subaccount=None, blz='_BLZ_'), SEPAAccount(iban='DE05_BLZ__SPARKONTO_', bic='BIC', accountnumber='_SPARKONTO_', subaccount=None, blz='_BLZ_')]

❯ cat config.yml
fints:
  blz: "_BLZ_"
  account: "_VRKENNUNG_"
  selectedAccount: "DE72_BLZ__GIROKONTO1_"
  password: "_PIN_"
  endpoint: "https://hbci-pintan.gad.de/cgi-bin/hbciservlet"
ledger:
  prompts:
    - credit_account
    - debit_account
  autocomplete:
    accounts:
      - credit_account
      - debit_account
  defaults:
    debit_account: assets:bank:checking
  md5:
    - date
    - payee
    - purpose
    - amount
MoritzR commented 4 years ago

That looks better, use _GIROKONTO1_ for the selectedAccount and it should work.

varac commented 4 years ago

Ahh, looks like I'm one step further, now I get a TypeError: 'NeedTANResponse' object is not iterable:

❯ fints2ledger --ledger-file ~/.config/fints2ledger/test.ledger               
You should register your program with the ZKA and pass your own product_id as a parameter.
Traceback (most recent call last):
  File "/home/varac/.config/fints2ledger/.direnv/python-venv-3.7.5/bin/fints2ledger", line 10, in <module>
    sys.exit(main())
  File "/home/varac/.config/fints2ledger/.direnv/python-venv-3.7.5/lib/python3.7/site-packages/fints2ledger/main.py", line 9, in main
    Fints2Csv(config).retrieveAndSave()
  File "/home/varac/.config/fints2ledger/.direnv/python-venv-3.7.5/lib/python3.7/site-packages/fints2ledger/fints2csv.py", line 24, in retrieveAndSave
    transaction), retriever.get_hbci_transactions(self.config["fints"]["start"], Date.today())))
TypeError: 'NeedTANResponse' object is not iterable
MoritzR commented 4 years ago

There is documentation on the python-fints documentation on how to work with TAN responses: https://python-fints.readthedocs.io/en/stable/tans.html

I cannot test this because my bank doesn't request a TAN.

If you want you can try to modify the code yourself to get it to work with the TAN mechanism. Feel free to contribute!

varac commented 4 years ago

Some banks (including mine) require a TAN when requesting transactions for more than 3 month. If fints2ledger is not able to deal with TANs I suggest to reduced the date default to 3 month ago, but this is only a UX improvement.

I'm still stuck because now I get a fints.exceptions.FinTSClientPINError: Error during dialog initialization, PIN wrong? error again, with the same config I tried in my last comment (I have it checked into git), where I was asked for a TAN. I am using buchhaltung right now to fetch my transaction details and it still works, so my fetching transctoins doesn't get blocked my bank which I initially thought.

varac commented 4 years ago

Dang, right in between my trouble with fints2ledger my bank disabled the VRKENNUNG as account identifier for fints. Now I use the new VR Net key and it works now (at least I got further). Thx for helping !

varac commented 2 years ago

I ran into this error again, good luck that I had my config in version control. I'm using a wrapper script that generates differnt config file from a fints2ledger config template, and in there I'm using yq. Turns out that after an yq update the selectedAccount number was indeed written as number and not as a string.

So selectedAccount: 123456789 will fail with the above error, while selectedAccount: "123456789" works.

MoritzR commented 2 years ago

That's good to know. Sounds like I should add a validation there so that using selectedAccount: 12345678 produces a better error message.