pyitau icon indicating copy to clipboard operation
pyitau copied to clipboard

AttributeError: 'NoneType' object has no attribute 'group'

Open danhenriquesc opened this issue 1 year ago • 3 comments

Since yesterday I started receiving the following error when loading account statement

Traceback (most recent call last):
  File "/Users/danielcosta/Documents/Projects/FinanceControl/./main.py", line 49, in <module>
    itau_bank_account_transactions = get_itau_bank_account_expenses(itau_account, month, year)
  File "/Users/danielcosta/Documents/Projects/FinanceControl/itau_bank_account.py", line 8, in get_itau_bank_account_expenses
    statement = itau_account.get_statements_from_month(month=month, year=year)
  File "/Users/danielcosta/Library/Python/3.9/lib/python/site-packages/pyitau/main.py", line 101, in get_statements_from_month
    "op": self._checking_full_statement_page.filter_statements_by_month_op
  File "/Users/danielcosta/Library/Python/3.9/lib/python/site-packages/pyitau/pages.py", line 256, in filter_statements_by_month_op
    return re.search(pattern, self._text, flags=re.DOTALL).group(1)
AttributeError: 'NoneType' object has no attribute 'group'

danhenriquesc avatar Feb 04 '24 00:02 danhenriquesc

+1 facing the same issue. (only for checking account, credit card still working fine)

rodrimaia avatar Feb 05 '24 13:02 rodrimaia

Now I'm getting this error: "[222] @property def full_statement_op(self): return self._soup.find("a").attrs["data-op"]

KeyError: 'data-op''" Does anyone know what could be causing this?

FernandoGaspar avatar Feb 06 '24 02:02 FernandoGaspar

So, even after the new release, I still had the same issue as @FernandoGaspar mentioned.

After debugging for a while, I realized the find("a") returns only the first item on that Menu, which doesn't have the data-op attribute. I don't know if Itau switched the menu order or something, but I realized the second item on that menu was exactly what we were looking for at that time. So I locally just changed to use the second link:

return self._soup.find_all("a")[1].attrs["data-op"]

I am aware this is not the most reliable solution, so maybe would be nice to filter all the links on that menu to find the one which has the link to the statements page (using the link name/title maybe??). if you guys have any idea how to do the filtering I would be happy to open a PR for it.

@FernandoGaspar can you try the same patch and see if it fixes the issue for you?

rodrimaia avatar Feb 09 '24 17:02 rodrimaia