From: lemoer Date: Mon, 10 Feb 2025 11:38:32 +0000 (+0100) Subject: Improve code example in docs/tans.rst (#184) X-Git-Tag: v4.2.4~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=87106bb775a8b8573034d25889b89a2c22f3259c;p=thirdparty%2Fpython-fints.git Improve code example in docs/tans.rst (#184) * Add product_id to example in docs/tans.rst * Fix initial tan request in example in docs/tans.rst Before this commit, the example suggested that we should only ask for a TAN after calling client.get_transactions(). This did not work (at least for my bank Sparkasse Hannover). Now with this commit, the example is proposing to ask for a TAN already in the beginning, as also suggested in docs/trouble.rst. Another side effect of this commit is that ask_for_tan() now also checks for response.decoupled and presents a more reasonable string for input() in the case of PushTAN. --- diff --git a/docs/tans.rst b/docs/tans.rst index f3a3eed..432bac8 100644 --- a/docs/tans.rst +++ b/docs/tans.rst @@ -206,12 +206,32 @@ A full example on how to get transactions if a TAN is required. If a TAN is requ from credentials import blz, username, password, hbci_backend + product_id = "CHANGE_ME" + + def ask_for_tan(f, response): + print("A TAN is required") + print(response.challenge) + if getattr(response, 'challenge_hhduc', None): + try: + terminal_flicker_unix(response.challenge_hhduc) + except KeyboardInterrupt: + pass + if response.decoupled: + tan = input('Please press enter after confirming the transaction in your app:') + else: + tan = input('Please enter TAN:') + return f.send_tan(response, tan) + client = FinTS3PinTanClient(blz, username, password, - hbci_backend) + hbci_backend, + product_id=product_id) minimal_interactive_cli_bootstrap(client) with client: + while isinstance(client.init_tan_response, NeedTANResponse): + client.init_tan_response = ask_for_tan(client, client.init_tan_response) + accounts = client.get_sepa_accounts() for account in accounts: print(f"Doing {account.iban}") @@ -219,17 +239,7 @@ A full example on how to get transactions if a TAN is required. If a TAN is requ start_date=datetime.datetime.now() - datetime.timedelta(days=100), end_date=datetime.datetime.now()) if isinstance(result, NeedTANResponse): - print("TAN is required") - if getattr(result, 'challenge_hhduc', None): - # Smart-TAN with flicker - try: - terminal_flicker_unix(result.challenge_hhduc) - except KeyboardInterrupt: - pass - # else: mobile TAN/manual Smart-TAN/... is used - print(result.challenge) - tan = input('Please enter TAN:') - result = client.send_tan(result, tan) + result = ask_for_tan(client, result) else: print("No TAN is required") print(f"Got {len(result)} transactions for {account.iban}")