我有一個 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中文網其他相關文章!

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)效率化,效率化,矢量化函數函數函數函數構成和穩定性構成和穩定性的操作,製造

數組的同質性對性能的影響是雙重的:1)同質性允許編譯器優化內存訪問,提高性能;2)但限制了類型多樣性,可能導致效率低下。總之,選擇合適的數據結構至關重要。

到CraftCraftExecutablePythcripts,lollow TheSebestPractices:1)Addashebangline(#!/usr/usr/bin/envpython3)tomakethescriptexecutable.2)setpermissionswithchmodwithchmod xyour_script.3)

numpyArraysareAreBetterFornumericalialoperations andmulti-demensionaldata,而learthearrayModuleSutableforbasic,內存效率段

numpyArraySareAreBetterForHeAvyNumericalComputing,而lelethearRayModulesiutable-usemoblemory-connerage-inderabledsswithSimpleDatateTypes.1)NumpyArsofferVerverVerverVerverVersAtility andPerformanceForlargedForlargedAtatasetSetsAtsAndAtasEndCompleXoper.2)

ctypesallowscreatingingangandmanipulatingc-stylarraysinpython.1)usectypestoInterfacewithClibrariesForperfermance.2)createc-stylec-stylec-stylarraysfornumericalcomputations.3)passarraystocfunctions foreforfunctionsforeffortions.however.however,However,HoweverofiousofmemoryManageManiverage,Pressiveo,Pressivero


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具

Atom編輯器mac版下載
最受歡迎的的開源編輯器

WebStorm Mac版
好用的JavaScript開發工具

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能