我有一个 python 代码来调用图形 api 并浏览共享点上的目录。该目录有 120gb 的文件,需要数小时才能扫描。但是,我观察到该脚本仅显示为在 visual studio 代码上运行,并且没有进一步执行。我在循环中打印文件名,一小时后它停止输入文件名。
是否是因为 token 一小时后就过期了?如果是,为什么我没有收到指示令牌无效的错误?
# Define imports import requests # Copy access_token and specify the MS Graph API endpoint you want to call, e.g. 'https://graph.microsoft.com/v1.0/groups' to get all groups in your organization #access_token = '{ACCESS TOKEN YOU ACQUIRED PREVIOUSLY}' url = "[URL TO THE SHAREPOINT]" headers = { 'Authorization': access_token } consentfilecount=0 clientreportcount = 0 graphlinkcount = 0 while True:# #print(graph_result.json()['@odata.nextLink']) graph_result = requests.get(url=url, headers=headers) if ('value' in graph_result.json()): for list in graph_result.json()['value']: if(("Client Consent Form").lower() in list["name"].lower()): consentfilecount +=1 print(list["name"]) if(("Final Client Report").lower() in list["name"].lower()): clientreportcount +=1 print(list["name"]) #print(graph_result.json()) if('@odata.nextLink' in graph_result.json()): url = graph_result.json()['@odata.nextLink'] graphlinkcount += 1 else: break print(consentfilecount)
正确答案
您所描述的行为几乎可以肯定是由于您似乎使用的不记名令牌确实仅在一个小时左右有效。
默认情况下,requests
does not raise exceptions based solely on HTTP status codes 允许开发人员选择他们想要如何处理此类情况。在您的情况下,您的 while true:
循环只是继续运行,成功解析从错误响应返回的 json 结构,但从未真正满足块内的任何条件。
如果您确实希望脚本在不成功的 http 响应代码上引发异常,您可以添加对 raise_for_status()
的调用:
graph_result = requests.get(url=url, headers=headers) graph_result.raise_for_status()
但是,如果您的代码预计正常运行时间超过令牌的有效期,您可能应该在代码中使用正确的 oauth 刷新流程,以防止发生此类错误。
以上是Azure 不记名令牌生命周期的详细内容。更多信息请关注PHP中文网其他相关文章!

Pythonarrayssupportvariousoperations:1)Slicingextractssubsets,2)Appending/Extendingaddselements,3)Insertingplaceselementsatspecificpositions,4)Removingdeleteselements,5)Sorting/Reversingchangesorder,and6)Listcomprehensionscreatenewlistsbasedonexistin

NumPyarraysareessentialforapplicationsrequiringefficientnumericalcomputationsanddatamanipulation.Theyarecrucialindatascience,machinelearning,physics,engineering,andfinanceduetotheirabilitytohandlelarge-scaledataefficiently.Forexample,infinancialanaly

useanArray.ArarayoveralistinpythonwhendeAlingwithHomeSdata,performance-Caliticalcode,orinterFacingWithCcccode.1)同质性data:arrayssavememorywithtypedelements.2)绩效code-performance-clitionalcode-clitadialcode-critical-clitical-clitical-clitical-clitaine code:araysofferferbetterperperperformenterperformanceformanceformancefornalumericalicalialical.3)

不,notalllistoperationsareSupportedByArrays,andviceversa.1)arraysdonotsupportdynamicoperationslikeappendorinsertwithoutresizing,wheremactssperformance.2)listssdonotguaranteeconeeconeconstanttanttanttanttanttanttanttanttimecomplecomecomecomplecomecomecomecomecomecomplecomectaccesslikearrikearraysodo。

toAccesselementsInapythonlist,useIndIndexing,负索引,切片,口头化。1)indexingStartSat0.2)否定indexingAccessesessessessesfomtheend.3)slicingextractsportions.4)iterationerationUsistorationUsisturessoreTionsforloopsoreNumeratorseforeporloopsorenumerate.alwaysCheckListListListListlentePtotoVoidToavoIndexIndexIndexIndexIndexIndExerror。

Arraysinpython,尤其是Vianumpy,ArecrucialInsCientificComputingfortheireftheireffertheireffertheirefferthe.1)Heasuedfornumerericalicerationalation,dataAnalysis和Machinelearning.2)Numpy'Simpy'Simpy'simplementIncressionSressirestrionsfasteroperoperoperationspasterationspasterationspasterationspasterationspasterationsthanpythonlists.3)inthanypythonlists.3)andAreseNableAblequick

你可以通过使用pyenv、venv和Anaconda来管理不同的Python版本。1)使用pyenv管理多个Python版本:安装pyenv,设置全局和本地版本。2)使用venv创建虚拟环境以隔离项目依赖。3)使用Anaconda管理数据科学项目中的Python版本。4)保留系统Python用于系统级任务。通过这些工具和策略,你可以有效地管理不同版本的Python,确保项目顺利运行。

numpyarrayshaveseveraladagesoverandastardandpythonarrays:1)基于基于duetoc的iMplation,2)2)他们的aremoremoremorymorymoremorymoremorymoremorymoremoremory,尤其是WithlargedAtasets和3)效率化,效率化,矢量化函数函数函数函数构成和稳定性构成和稳定性的操作,制造


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

MinGW - 适用于 Windows 的极简 GNU
这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

Atom编辑器mac版下载
最流行的的开源编辑器

VSCode Windows 64位 下载
微软推出的免费、功能强大的一款IDE编辑器

SublimeText3 Linux新版
SublimeText3 Linux最新版

DVWA
Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中