wea*_*erk 5 python sharepoint sharepoint-2013
我正在使用此库https://github.com/ox-it/python-sharepoint连接到SharePoint列表.我可以进行身份验证,访问列表字段,包括我想要的文件的完整URL,看起来这个库确实有is_file()和open()方法,但我不明白如何调用这些.任何建议表示赞赏!
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() ??
Run Code Online (Sandbox Code Playgroud)
引用自述文件:
对文档库的支持有限,但SharePointListRow对象支持is_file()方法和open()方法来访问文件数据.
基本上,您在列表行(类型为SharePointListRow)上调用这些方法。该方法实际上是urllib2open()的 opener的方法,您通常使用它,如下所示:
import urllib2
opener = urllib2.build_opener()
response = opener.open('http://www.example.com/')
print ('READ CONTENTS:', response.read())
print ('URL :', response.geturl())
# ....
Run Code Online (Sandbox Code Playgroud)
所以你应该能够像这样使用它(不过我没有任何 Sharepoint 网站来检查这一点):
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, e.g. write to disk
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15187 次 |
| 最近记录: |