andreroggeri/pynubank

TypeError: 'NoneType' object is not iterable

Closed this issue · 2 comments

Hi, getting the following error when I call nu.get_account_statements(). Has anyone seen this before? My unchanged daily script started erroring out yesterday. Maybe nubank's API has changed?

Traceback (most recent call last):
  File "/_/projects/numbers/finance.py", line 175, in <module>
    import_nubank()
  File "/_/projects/numbers/finance.py", line 63, in import_nubank
    account_rows = nu.get_account_statements()
  File "/usr/local/anaconda3/lib/python3.8/site-packages/pynubank/auth_mode.py", line 23, in wrapper
    return function(*args, **kwargs)
  File "/usr/local/anaconda3/lib/python3.8/site-packages/deprecated/classic.py", line 285, in wrapper_function
    return wrapped_(*args_, **kwargs_)
  File "/usr/local/anaconda3/lib/python3.8/site-packages/pynubank/nubank.py", line 209, in get_account_statements
    feed = map(parse_pix_transaction, feed)
TypeError: 'NoneType' object is not iterable

This is a known issue, it seems that nubank is deprecating this endpoint in favor of the paginated one.

Can you try it and check if it works with you?

Opa, that was more work than I anticipated, since get_account_statements_paginated returns a different record structure 😀 . Below is a snippet to gather all records for past 4 weeks into account_rows (with similar structure as get_account_statements).

Thank you! I'll close this.

  DATE_ANCHOR = str(datetime.today() - timedelta(weeks=4)).split()[0]

  account_rows = []
  feed = nu.get_account_statements_paginated()
  account_rows += [e['node'] for e in feed['edges']]
  has_next_page = feed['pageInfo']['hasNextPage']
  while has_next_page:
    cursor = feed['edges'][-1]['cursor']
    feed = nu.get_account_feed_paginated(cursor)
    account_rows += [e['node'] for e in feed['edges']]
    has_next_page = feed['pageInfo']['hasNextPage']
    if account_rows[-1]['postDate'] < DATE_ANCHOR: break