Mastodon.py icon indicating copy to clipboard operation
Mastodon.py copied to clipboard

TypeError on automated pagination

Open FedericoCeratto opened this issue 1 year ago • 2 comments

Hello and thanks for developing this library.

mastodon.fetch_next called on an empty list of toots leads to:

  File "/usr/lib/python3/dist-packages/mastodon/utility.py", line 206, in fetch_next
    method = params['_pagination_method']
             ~~~~~~^^^^^^^^^^^^^^^^^^^^^^
TypeError: list indices must be integers or slices, not str

Steps to reproduce:

toots = mastodon.timeline()
while True:
    toots = mastodon.fetch_next(toots)

It seems that fetch_next returns an empty list after 800 toots and breaks the next run. Perhaps the library could provide an iterator that terminates at the end instead?

Thanks!

FedericoCeratto avatar May 06 '23 12:05 FedericoCeratto

yeah, that sounds like a really good idea, actually.

Workshopping this in my head, so I'm wondering, what do (or others) you think would make more sense:

  • An iterator that iterates pages?
  • An iterator that iterates post and fetches next page as needed?
  • Both?

halcy avatar May 11 '23 11:05 halcy

Late to the party, but IMHO, option 2 (An iterator that iterates post and fetches next page as needed?) seems better.

gglanzani avatar Jun 25 '24 03:06 gglanzani