How to upload a file using python-sharepoint library

I use this library https://github.com/ox-it/python-sharepoint to connect to a SharePoint list. I can authenticate access to the list fields, including the full URL of the file I want, and it looks like this library has is_file() and open() methods, but I don’t understand how to name them. Any advice is appreciated!

 from sharepoint import SharePointSite, basic_auth_opener opener = basic_auth_opener(server_url, "domain/username", "password") site = SharePointSite(server_url, opener) sp_list = site.lists['ListName'] for row in sp_list.rows: print row.id, row.Title, row.Author['name'], row.Created, row.EncodedAbsUrl #download file #row.open() ?? 

To quote a ReadMe file:

Document library support is limited, but SharePointListRow objects support the is_file () method and the open () method for accessing data files.

+5
source share
1 answer

You basically call these methods on a list line (which is of type SharePointListRow ). The open() method is actually a urllib2 method, which you usually use like this:

 import urllib2 opener = urllib2.build_opener() response = opener.open('http://www.example.com/') print ('READ CONTENTS:', response.read()) print ('URL :', response.geturl()) # .... 

So you should be able to use it like this (I don't have a Sharepoint site to check this out):

 from sharepoint import SharePointSite, basic_auth_opener opener = basic_auth_opener(server_url, "domain/username", "password") site = SharePointSite(server_url, opener) sp_list = site.lists['ListName'] for row in sp_list.rows(): # <<< print row.id, row.Title, row.Author['name'], row.Created, row.EncodedAbsUrl # download file here print ( "This row: ", row.name() ) # <<< if row.is_file(): # <<< response = row.open() # <<< file_data = response.read() # <<< # process the file data, eg write to disk 
+2
source

All Articles