lucasrcezimbra / pyitau

Unofficial client to access your Itaú bank data
https://pypi.org/project/pyitau/
GNU Lesser General Public License v2.1
51 stars 15 forks source link

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

Open danhenriquesc opened 9 months ago

danhenriquesc commented 9 months ago

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'
rodrimaia commented 9 months ago

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

FernandoGaspar commented 9 months ago

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?

rodrimaia commented 8 months ago

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?