Python连接Sharepoint Online认证问题

mandielow 2020-07-14 11:32:21
使用shareplum,但一直无法认证通过,返回错误。
请指导或使用其他方式连接认证也可。


from shareplum import Site
from shareplum import Office365
from shareplum.site import Version


sharepointUsername = "abc@xyz.com"

sharepointPassword = "abc@123"

sharepointSite = "https://abc.sharepoint.cn/sites/mysite"

website = "https://abc.sharepoint.cn"

authcookie = Office365(website, username=sharepointUsername,password=sharepointPassword).GetCookies()

site = Site(sharepointSite, version=Version.v365, authcookie=authcookie)


返回错误如下:
Exception: ('Error authenticating against Office 365. Was not able to find an error code. Here is the SOAP response from Office 365', b'<?xml version="1.0" encoding="utf-8"?><S:Envelope xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wst="http://schemas.xmlsoap.org/ws/2005/02/trust" xmlns:S="http://www.w3.org/2003/05/soap-envelope"><S:Header><wsa:Action S:mustUnderstand="1" wsu:Id="Action">http://schemas.xmlsoap.org/ws/2005/02/trust/RSTR/Issue</wsa:Action><wsa:To S:mustUnderstand="1" wsu:Id="To">http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To><wsse:Security S:mustUnderstand="1"><wsu:Timestamp wsu:Id="TS" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><wsu:Created>2020-07-14T03:16:02.0376486Z</wsu:Created><wsu:Expires>2020-07-14T03:21:02.0376486Z</wsu:Expires></wsu:Timestamp></wsse:Security></S:Header><S:Body xmlns:S="http://www.w3.org/2003/05/soap-envelope"><wst:RequestSecurityTokenResponse xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wst="http://schemas.xmlsoap.org/ws/2005/02/trust"><wsp:AppliesTo><wsa:EndpointReference xmlns:wsa="http://www.w3.org/2005/08/addressing"><wsa:Address>https://twsgroup.sharepoint.cn</wsa:Address></wsa:EndpointReference></wsp:AppliesTo><psf:pp xmlns:psf="http://schemas.microsoft.com/Passport/SoapServices/SOAPFault"><psf:reqstatus>0x8004882c</psf:reqstatus><psf:errorstatus>0x80045b00</psf:errorstatus></psf:pp></wst:RequestSecurityTokenResponse></S:Body></S:Envelope>')
...全文
270781 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
霖雨 版主 2021-03-09
  • 打赏
  • 举报
回复
是个好问题,同求结果~
mandielow 2020-12-08
  • 打赏
  • 举报
回复
并没有解决...我们后来把连接从sharepoint改到onedrive上, 暂时满足了原来需求了~
weixin_41613239 2020-11-26
  • 打赏
  • 举报
回复
这个问题解决了吗? Mandielow 楼主!面临相同的问题
Justin-Liu 2020-07-21
  • 打赏
  • 举报
回复
错误信息挺明白,你到github上看看吧,我这上不去
Justin-Liu 2020-07-20
  • 打赏
  • 举报
回复
https://pypi.org/project/Office365-REST-Python-Client/ 试试这个,我这连不了SharePoint没法试
mandielow 2020-07-20
  • 打赏
  • 举报
回复
引用 1 楼 Justin-Liu 的回复:
https://pypi.org/project/Office365-REST-Python-Client/ 试试这个,我这连不了SharePoint没法试
尝试了但同样报错, 如下:

from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.sharepoint.client_context import ClientContext

ctx_auth = AuthenticationContext("https://abc.sharepoint.cn")
if ctx_auth.acquire_token_for_user("abc@tws.com", "abc123"):
  ctx = ClientContext(url, ctx_auth)
  web = ctx.web
  ctx.load(web)
  ctx.execute_query()
  print("Web title: {0}".format(web.properties['Title']))

else:
  print(ctx_auth.get_last_error())
错误信息:Cannot get binary security token for from https://login.microsoftonline.com/extSTS.srf KeyError: 'FedAuth' 点入错误信息中的链接则是微软官方错误信息:The endpoint only accepts POST requests. Received a GET request.

3,242

社区成员

发帖
与我相关
我的任务
社区描述
企业开发 SharePoint
社区管理员
  • SharePoint社区
  • 霖雨
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧