Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Can't get state restoring running #158

Open
yanone opened this issue Jan 29, 2024 · 0 comments
Open

Can't get state restoring running #158

yanone opened this issue Jan 29, 2024 · 0 comments

Comments

@yanone
Copy link

yanone commented Jan 29, 2024

I read the documentation, but it's not immediately clear to me what to do.

I have put together the following code from the examples. In reality, a TAN is only required for the transactions, not for the balance, so the first TAN query never executes. I want to achieve that I have to enter a TAN only every couple of months like how it works for my banking app, but I can't understand from the documentation how to save the state.

It's probably just a minor mistake. Please help.

def kontostand(failOnError=False):
    blz = "***"
    login = "***"
    key_id = f"{blz}.{login}"
    password = keyring.get_password("fints", key_id)
    if not password:
        password = getpass.getpass("PIN:")
        keyring.set_password("fints", key_id, password)

    # Restore state
    tan_data = None
    if os.path.exists("tan.data"):
        with open("tan.data", "rb") as f:
            tan_data = f.read()

    client = FinTS3PinTanClient(
        blz,  # Your bank's BLZ
        login,  # Your login name
        password,  # Your banking PIN
        "https://fints1.atruvia.de/cgi-bin/hbciservlet",
        product_id="6151256F3D4F9975B877BD4A2",  # https://community.home-assistant.io/t/fints-access-needs-product-id/322464/4
        from_data=tan_data,
    )

    minimal_interactive_cli_bootstrap(client)
    with client:
        # Since PSD2, a TAN might be needed for dialog initialization.
        # Let's check if there is one required
        if client.init_tan_response:
            if failOnError:
                raise Exception("A TAN is required. Run tan.py separately.")
            else:
                print("A TAN is required", client.init_tan_response.challenge)
                tan = input("Please enter TAN:")
                client.send_tan(client.init_tan_response, tan)

        # Fetch accounts
        accounts = client.get_sepa_accounts()
        balance = client.get_balance(accounts[0])

        transactions = client.get_transactions_xml(accounts[0])
        if isinstance(transactions, NeedTANResponse):
            print("Eine TAN wird benötigt!")
            print(transactions.challenge)
            tan = input("TAN:")
            transactions = client.send_tan(transactions, tan)

        client_data = client.deconstruct()

        # Save state
        with open("tan.data", "wb") as f:
            f.write(client_data)

        return balance.amount.amount, transactions
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant