jasonrollins / shareplum

Pythonic SharePoint
MIT License
179 stars 96 forks source link

error pulling out > 5000 list items #167

Open sme31 opened 3 years ago

sme31 commented 3 years ago

I am (a novice) using shareplum to upload 35,000 documents to a single document library, and when I get to 5,000 documents I'm getting a 500 Server Error.

The process I am using is to upload the file, and then set the metadata using this module. (Not my code, I've taken it from here https://multiportmedia.com/uploading-files-to-sharepoint-using-python-part-1/)

def addMeta(self): instanceOfDocumentLibrary = self.site.List(self.sharePointFolder) fields = ['Name', 'ID'] query = {'Where': [('Contains', 'Name', self.fileName)]} GetData = instanceOfDocumentLibrary.GetListItems(fields=fields, query=query) getDataDict = GetData[-1] util = Util() payload = util.mergeDict(getDataDict, self.customeMetaDict) update_data = [payload] instanceOfDocumentLibrary.UpdateListItems(data=update_data,kind='Update')

The error is generated when the GetData line is executed. The file gets uploaded fine (by a different module), but fails in this module. I suspect what is happening is that when the List is instantiated (instanceOfDocumentLibrary) it only contains 5,000 documents (as per the SharePoint 5,000 document view limit), and so when we do the GetListItems it can't find the 5,001th document that we've just uploaded because instanceOfDocumentLibrary only contains 5,000 documents.

Dipping into the Shareplum code (list.py) I see row_limit=0, which in the comments says the row limit should be unlimited, but I suspect it isn't unlimited. Could it be that leaving row_limit=0, it is defaulting to 5,000 (i.e. the SharePoint view limit)? If we make row_limit=50,000 (for example) would that solve the issue?

Way out of my depth here, so any suggestions more than welcome.

Thanks

jasonrollins commented 3 years ago

This is a limitation of your SharePoint server, that is put in by default by Microsoft. You won't be able to get around it, unless you are the administrator of your SharePoint site and can increase this limit.

On Mon, Jun 28, 2021 at 4:33 AM sme31 @.***> wrote:

I am (a novice) using shareplum to upload 35,000 documents to a single document library, and when I get to 5,000 documents I'm getting a500 Server Error.

The process I am using is to upload the file, and then set the metadata using this module. (Not my code, I've taken it from here https://multiportmedia.com/uploading-files-to-sharepoint-using-python-part-1/ )

def addMeta(self): instanceOfDocumentLibrary = self.site.List(self.sharePointFolder) fields = ['Name', 'ID'] query = {'Where': [('Contains', 'Name', self.fileName)]} GetData = instanceOfDocumentLibrary.GetListItems(fields=fields, query=query) getDataDict = GetData[-1] util = Util() payload = util.mergeDict(getDataDict, self.customeMetaDict) update_data = [payload] instanceOfDocumentLibrary.UpdateListItems(data=update_data,kind='Update')

The error is generated when the GetData line is executed. The file gets uploaded fine, but fails in this module. I suspect what is happening is that when the List is instantiated (instanceOfDocumentLibrary) it only contains 5,000 documents (as per the SharePoint 5,000 document view limit), and so when we do the GetListItems it can't find the 5,001th document that we've just uploaded because instanceOfDocumentLibrary only contains 5,000 documents.

Dipping into the Shareplum code (list.py) I see row_limit=0, which in the comments says the row limit should be unlimited, but I suspect it isn't unlimited. Could it be that leaving row_limit=0, it is defaulting to 5,000 (i.e. the SharePoint view limit)? If we make row_limit=50,000 (for example) would that solve the issue?

Way out of my depth here, so any suggestions more than welcome.

Thanks

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jasonrollins/shareplum/issues/167, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOVTVUZF4MWPJCSTUKJIODTVA6XVANCNFSM47NSUALA .

sme31 commented 3 years ago

Thanks for the reply, Jason. I should have mentioned that I am using Sharepoint online, where I think the limit is pretty much fixed. It's interesting to see though that some folks using javascript have worked out a way to do this https://sharepoint.stackexchange.com/questions/217254/rest-to-read-more-than-5000-items-from-document-library so I may move over to that environment to see if I can make headway that way.

oederp1 commented 2 years ago

I have the same problem. Does anyone have a solution to read a list with more than 5000 records?

sme31 commented 2 years ago

I resolved my issue by not using Shareplum, and using https://github.com/vgrem/Office365-REST-Python-Client