从sharepoint rest api下载文件时出现400错误

编程入门 行业动态 更新时间:2024-10-19 10:26:45
本文介绍了从sharepoint rest api下载文件时出现400错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用 Python 通过 REST API 从 sharepoint 下载文件.这是我的代码:

I am trying to download files from sharepoint through REST API using Python. Here is my code:

import requests from requests_ntlm import HttpNtlmAuth req = requests.get("sharepoint/sites/publishing/sales/_api/web/getfilebyserverrelativeurl('\Documents\Folder\data_04202015.csv')",auth=HttpNtlmAuth('domain\\username','password')) print req.status_code

如果请求的网址是sharepoint/sites/publishing/sales/_api/web" 返回码将是 200 ok,但是当尝试使用 GetFileByServerRelativeUrl 时,它将返回 400.

If the requested url is "sharepoint/sites/publishing/sales/_api/web" the return code will be 200 ok, but when trying with GetFileByServerRelativeUrl, it will return 400.

推荐答案

最后,我可以使用 共享点库

文件路径如下:sharepoint/sites/publishing/sales/Sales_Distribution/Data/record.csv

请注意,如果您尝试访问文件夹下的文件,则必须从/sites/... 指定路径根目录

Please note that if you are trying to access files under a folder, you have to specify the path roots from /sites/...

from sharepoint import SharePointSite, basic_auth_opener import urllib2 from ntlm import HTTPNtlmAuthHandler user = 'domain\username' password = "password" server_url = "sharepoint/" site_url = server_url + "sites/publishing/sales/" passman = urllib2.HTTPPasswordMgrWithDefaultRealm() passman.add_password(None, site_url, user, password) auth_NTLM = HTTPNtlmAuthHandler.HTTPNtlmAuthHandler(passman) opener = urllib2.build_opener(auth_NTLM) urllib2.install_opener(opener) site = SharePointSite(site_url, opener) salesList = site.lists['Sales Distribution'] fileList = salesList.get_rows(folder='/sites/publishing/sales/Sales_Distribution/Data') print "=================================" url = fileList[5].as_dict()['EncodedAbsUrl'] file = fileList[5].open() content = urllib2.urlopen(url) print content.read()

更多推荐

从sharepoint rest api下载文件时出现400错误

本文发布于:2023-11-28 10:01:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1641949.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   文件   rest   sharepoint   api

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!