尊敬的先生,
你能帮我找出为什么我不再连接到 sharepoint 了吗?
使用 2.2.2 版,一切正常。
然后出现问题 #272(从 XML 响应中检索令牌时发生错误:AADSTS500069)所以我升级到 2.3.0.1。
现在以下代码也不起作用:
def copy_sharepoint(self,filename=""):
ctx = ClientContext(self.SITE_SHAREPOINT).with_credentials(UserCredential(self.WIN_USER,self.WIN_PASSWORD))
localpath=os.path.join(self.CHEMIN_XLSX,self.NOM_TIR + '/',self.FICHIER_BI)
self.print_debug("",localpath)
self.print_debug("",self.WIN_PASSWORD)
使用 open(localpath, 'rb') 作为 content_file:
file_content = content_file.read()
文件 = ctx.web.get_folder_by_server_relative_url(self.CHEMIN_SHAREPOINT).upload_file(self.FICHIER_BI, file_content).execute_query()
回溯(最近一次调用最后一次):
文件“/appli/sopra/tools/tir_bench.py”,第 1327 行,在
tir_bench.copy_sharepoint()
文件“/appli/sopra/tools/tir_bench.py”,第 1278 行,在 copy_sharepoint
文件 = ctx.web.get_folder_by_server_relative_url(self.CHEMIN_SHAREPOINT).upload_file(self.FICHIER_BI, file_content).execute_query()
文件“/home/benchsp/.local/lib/python3.9/site-packages/office365/runtime/client_object.py”,第30行,在execute_query
self.context.execute_query()
文件“/home/benchsp/.local/lib/python3.9/site-packages/office365/runtime/client_runtime_context.py”,第138行,execute_query
self.pending_request().execute_query()
文件“/home/benchsp/.local/lib/python3.9/site-packages/office365/runtime/client_request.py”,第 73 行,execute_query
self.beforeExecute.notify(请求)
文件“/home/benchsp/.local/lib/python3.9/site-packages/office365/runtime/types/EventHandler.py”,第18行,通知
听众(参数,* kwargs)
文件“/home/benchsp/.local/lib/python3.9/site-packages/office365/sharepoint/client_context.py”,第 162 行,在 _build_modification_query
self.ensure_form_digest(请求)
文件“/home/benchsp/.local/lib/python3.9/site-packages/office365/sharepoint/client_context.py”,第123行,在ensure_form_digest
self.request_form_digest()
文件“/home/benchsp/.local/lib/python3.9/site-packages/office365/sharepoint/client_context.py”,第 130 行,在 request_form_digest 中
response = self.execute_request_direct(request)
文件“/home/benchsp/.local/lib/python3.9/site-packages/office365/runtime/client_runtime_context.py”,第134行,在execute_request_direct中
返回 self.pending_request().execute_request_direct(request)
文件“/home/benchsp/.local/lib/python3.9/site-packages/office365/runtime/odata/odata_request.py”,第34行,在execute_request_direct中
return super(ODataRequest, self).execute_request_direct(request)
文件“/home/benchsp/.local/lib/python3.9/site-packages/office365/runtime/client_request.py”,第 86 行,execute_request_direct
self.context.authenticate_request(request_options)
文件“/home/benchsp/.local/lib/python3.9/site-packages/office365/sharepoint/client_context.py”,第151行,在authenticate_request
self._auth_context.authenticate_request(请求)
文件“/home/benchsp/.local/lib/python3.9/site-packages/office365/runtime/auth/authentication_context.py”,第84行,authenticate_request
self._provider.authenticate_request(request)
文件“/home/benchsp/.local/lib/python3.9/site-packages/office365/runtime/auth/providers/saml_token_provider.py”,第73行,authenticate_request
self.ensure_authentication_cookie()
文件“/home/benchsp/.local/lib/python3.9/site-packages/office365/runtime/auth/providers/saml_token_provider.py”,第80行,在ensure_authentication_cookie中
self._cached_auth_cookies = self.get_authentication_cookie()
文件“/home/benchsp/.local/lib/python3.9/site-packages/office365/runtime/auth/providers/saml_token_provider.py”,第93行,在get_authentication_cookie中
令牌 = self._acquire_service_token_from_adfs(user_realm.STSAuthUrl)
文件“/home/benchsp/.local/lib/python3.9/site-packages/office365/runtime/auth/providers/saml_token_provider.py”,第136行,_acquire_service_token_from_adfs
assertion_node = dom.getElementsByTagNameNS("urn:oasis:names:tc:SAML:1.0:assertion", 'Assertion')[0].toxml()
IndexError:列表索引超出范围
你能帮我解决这个问题吗?
提前致谢,
纪尧姆
你好,
另外,这里是 response.content.decode()) 的值
<value i="14">s:Sender</value><subcode i="15"><value i="16">a:InvalidSecurity</value></subcode>
问候!
感谢您提供详细的日志,目前我无法根据 SharePoint/ADFS 环境对其进行验证。
@wreiner ,也许您可以确认一下 _federated authentication_ 是否在您这边按预期工作以获取最新版本?
大家好
我遇到了类似的问题,以下行给出了 400 或 500 的响应。
如果我收到 400 响应,则正文为空,导致xml.parsers.expat.ExpatError: no element found: line 1, column 0
异常。 500 响应给出与@guillaume-colas 相同的异常。
我还没有让包工作,所以它很可能是 sharepoint 服务器,但我会尝试降级包以确保。 如何确保正确设置了共享点身份验证?
提前谢谢!
嗨,
我不在我的计算机上进行全面分析,但正如我所见,当我使用 pip 安装最新版本时,_runtime/auth/providers/saml_token_provider.py_ 中缺少函数 _acquire_service_token_from_adfs_。
在我的拉取请求中没有删除此功能,所以我不确定为什么它会丢失。 我对日期时间格式的修复也不在文件中。 也许合并有错误?
@wreiner谢谢你回来,关于
Acquire_service_token_from_adfs 丢失
它已从公共方法重构
我对日期时间格式的修复不在文件中
格式应该与最初提交的一样就位,但在将声明移动到sts_profile.py
方面对其进行了重构
self.created = now.astimezone(timezone.utc).isoformat('T')[:-9] + 'Z' self.expires = (now + timedelta(minutes=10)).astimezone(timezone.utc).isoformat('T')[:-9] + 'Z'
但如果合并后遗漏了什么,我应该受到指责。
大家好
我遇到了类似的问题,以下行给出了 400 或 500 的响应。
如果我收到 400 响应,则正文为空,导致
xml.parsers.expat.ExpatError: no element found: line 1, column 0
异常。 500 响应给出与@guillaume-colas 相同的异常。我还没有让包工作,所以它很可能是 sharepoint 服务器,但我会尝试降级包以确保。 如何确保正确设置了共享点身份验证?
提前谢谢!
嗨,马克,
感谢您的确认,它确实出现在最新版本的联合身份验证(SharePoint/ADFS)中
你能试试 _previous_ 版本 ( 2.2.2
) 吗?
我没有通过完整的分析,但是对于我的更改,我可以说它们正确返回了安全令牌和 cookie,但是 cookie jar 不包含在 is_valid_auth_cookies 中查找的“FedAuth”字段,该字段现在正在 _get_authentication_cookie 中使用。
对于联合身份验证,我只能在 jar 中看到 SPOIDCRL。
目前我仍然无法正确使用获得的身份验证数据,我仍在调查但不知道我需要多长时间。
总而言之,我可以说旧版本和我的补丁一切仍然按预期正常工作,但不幸的是新版本不行。
感谢您的快速回复:-)
@vgrem它在 2.2.2 版上得到了类似的错误,所以它似乎是共享点服务器。
将异常包装成一个更易读的异常可能会很好。
我又进了一步。 原来我需要重置我的密码。 我现在遇到了与@wreiner 相同的错误。 is_valid_auth_cookies
返回该 cookie 无效,因为字典仅包含 SPOIDCRL 密钥而没有 FedAuth 密钥。 如果我只是注释掉这个关于 cookie 是否有效的检查。 我可以从 sharepoint 下载文件。 所以身份验证似乎工作正常。
也许我会再次尝试 2.2.2 版。
我有同样的问题。 is_valid_auth_cookies
返回False
因为 cookies dict 中没有FedAuth
键。 如果我注释返回代码并简化返回 True,身份验证将正常工作。
def is_valid_auth_cookies(values):
return True
# return any(values) and values.get('FedAuth', None) is not None
嘿@hungnguyen95 ,谢谢你的确认!
结果is_valid_auth_cookies
需要调整。
你好,
我的问题会通过修改 is_valid_auth_cookies 来解决吗?
对不起,我很迷茫。 我认为我的问题出在 _acquire_service_token_from_adfs 中。
您知道为什么我会收到“无效的安全性”响应并希望有一种解决方法来进行身份验证吗?
预先感谢您的帮助。
纪尧姆
@guillaume-colas 看来您的问题可能与不允许您访问的服务器有关。 您确定密码正确吗?您是否尝试过重置密码? 重置我的密码解决了这个问题。 之后我遇到了is_valid_auth_cookies
问题。
@mark-boer 是的,我已经验证了我的密码并且它是正确的。 是否有可能是 2FA(短信代码)的身份验证阻止了身份验证?
是否可以使用 ClientCredentials 将文件上传到 sharepoint?
预先感谢您的帮助