Python Generator Object PageIterator.items

With the following code in Python I’m getting what I think are pagination errors. However, the similar API call in curl (via web browser) works with no errors at all.

------Python Code-----

client = asana.Client.access_token(personal_access_token)
tag_GID_planning = "932213312356783917"  #number is not real, changed for posting here, but is accurate in my code

# Get your user info
me =
Workspace = me['workspaces'][0] #set main workspace

planning_tag = client.tags.get_tag(tag_GID_planning, {'param': 'value', 'param': 'value'}, opt_pretty=True)
planning_tag_tasks = client.tasks.get_tasks_for_tag(tag_GID_planning, {'param': 'value', 'param': 'value'}, opt_pretty=True)
result = client.tags.get_tags({'param': 'value', 'param': 'value'}, opt_pretty=True)

--------End Code----------

planning_tag comes back use-able (right now I’m just printing it to the console with no issues).
planning_tag_tasks and results both are a “generator object” when I print these to the console I get the following “<generator object PageIterator.items at 0x000001C124CEC270>” as the error message.

I saw another post in this forum which indicated one doesn’t need to worry about pagination of results. It lead me to believe that Python code will do that on it’s own. However, these are small amounts of returns and work when the curl equivalent command is typed into a web browser. So I don’t think this is the issue.

All three of these are per the examples given in the API docs.

I’m not certain what I’m doing wrong and would appreciate any help or suggestions you may have.

Hey @Matthew_Josey, sorry for the delay. I only seldomly get on our forum these days :confused: although Ross and Jeff find their way here more often!

Python generators are a lazy-evaluating abstraction around sets of items. You can iterate through them in a for item in planning_tag_tasks: way and they allow us to handle things like pagination “under the hood” while returning items one by one. They are only guaranteed to be iterable, so if that iteration requries things like fetching new pages they let us do that in the background.

You can force them to fetch all their items by casting them to a structure that has different guarantees like an explicit in-memory list. Try print(list(planning_tag_tasks)) and see if that does what you expect!

1 Like