mloesch / sickle

Sickle: OAI-PMH for Humans
Other
106 stars 42 forks source link

Why token is invalid after iteration ? #12

Closed JBPressac closed 8 years ago

JBPressac commented 8 years ago

Hello, On Python 3.5.2 + Sickle 0.5, if we display the token after an iteration on a ListRecords, we get an AttributeError. Do you have any explanation about that ?

from sickle import Sickle

cm_sickle = Sickle('http://oai.openedition.org' )
records_original = cm_sickle.ListRecords(set='journals:cm', metadataPrefix='mets')
print(records_original.resumption_token.token) 
# Prints correctly the token

for record in records_original:
    print(record.raw)

print(records_original.resumption_token.token) 
# Error AttributeError: 'NoneType' object has no attribute 'token'

Thanks,

mloesch commented 8 years ago

When iterating over records, Sickle automatically handles the paging with resumption tokens for you. Therefore the following part of your code already iterates over all records found by the ListRecords query, not just the first page.

for record in records_original:
    print(record.raw)

Because there is no resumption token on the last page, the resumption_token property will be empty after the iteration.