你好,
我想一個python文件導入和Azure DevOps釋放管道磚。
管道內我執行一個python腳本包含這個代碼:
導入係統導入操作係統導入base64導入請求dbw_url =係統。argv [1] #https://adb-XXXXXXXXXXXXX.XX.azuredatabricks.net/令牌=係統。argv[2] #磚拍root_source = os.path.join (os.environ.get (“SYSTEM_DEFAULTWORKINGDIRECTORY”),工件_Build筆記本,artifact_dir_path) #這是一個結果從一個構建管道target_dir_path = ' /共享的文件= os.listdir (root_source)[0]張開(os.path打印(文件)。加入(root_source、文件),rb) f: data = base64.standard_b64encode (f.read ()) .decode (utf - 8) json ={“路徑”,“內容”:數據:os.path。加入(target_dir_path、文件),“語言”:“PYTHON”、“覆蓋”:真的,“格式”:“源”}import_notebook =請求。郵報》(“{}/ api / 2.0 / workspace /導入“.format (dbw_url),標題={“授權”:“不記名{}”.format(令牌)},json = json)打印(import_notebook.status_code) # - > 200
狀態碼是200但是沒有進口磚工作區。
這就是我在管道日誌:
2021 - 11 - 15 t14:39:54.0421229z # # sectionStarting:運行一個Python腳本2021 - 11 - 15 t14:39:54.0429015z = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 2021 - 11 - 15 - t14:39:54.0429348z任務:Python腳本2021 - 11 - 15 t14:39:54.0429590z描述:運行Python文件或內聯腳本2021 - 11 - 15 t14:39:54.0429815z版本:0.182.0 2021 - 11 - 15 t14:39:54.0430025z作者:微軟公司2021 - 11 - 15 t14:39:54.0430358z幫助:https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/python-script2021 - 11 - 15 t14:39:54.0430694z = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 2021 - 11 - 15 - t14:39:54.1829847z(命令)/ opt / hostedtoolcache / Python / 3.10.0 / x64 / bin / Python /home/vsts/work/_temp/2dfc3151 - 6 - ce7 4 - c6d a74e c767241——59125。py * * * * * * 2021 - 11 - 15 t14:39:54.4797958z ingest_csv。py 2021 - 11 - 15 t14:39:54.4798454z 200 2021 - 11 - 15 t14:39:54.5018448z # # sectionFinishing:運行一個Python腳本
這是工作好當我從本地機器上執行它。
注意:很奇怪,但是當我把* * * * *值的“令牌”變量,我獲得相同的結果:狀態碼200。然而,當我從本地機器上獲得一個錯誤。
謝謝你的幫助。
最近我寫了一篇關於替代方法導出/導入pthon筆記本https://community.www.eheci.com/s/question/0D53f00001TgT52CAF/import-notebook-with-python-script-us..。這樣你會得到更可讀的錯誤/信息(通常是相關的主機名或訪問權限)。
pip安裝databricks-cli
從databricks_cli.workspace。api從databricks_cli.sdk進口WorkspaceApi。api_client進口ApiClient客戶= ApiClient(主機= ' https://your.databricks-url.net ',令牌= api_key) workspace_api = WorkspaceApi workspace_api(客戶端)。import_workspace (source_path = " /你/ dir /這/你好。py”, target_path = " /回購/測試/你好。py”,覆蓋= True)
最近我寫了一篇關於替代方法導出/導入pthon筆記本https://community.www.eheci.com/s/question/0D53f00001TgT52CAF/import-notebook-with-python-script-us..。這樣你會得到更可讀的錯誤/信息(通常是相關的主機名或訪問權限)。
pip安裝databricks-cli
從databricks_cli.workspace。api從databricks_cli.sdk進口WorkspaceApi。api_client進口ApiClient客戶= ApiClient(主機= ' https://your.databricks-url.net ',令牌= api_key) workspace_api = WorkspaceApi workspace_api(客戶端)。import_workspace (source_path = " /你/ dir /這/你好。py”, target_path = " /回購/測試/你好。py”,覆蓋= True)