MLflow“無效訪問令牌”錯誤

長時間運行的ML任務需要一個具有延長生命周期的訪問令牌,以確保任務在令牌過期之前完成。

寫的shanmugavel.chandrakasu

最後發布日期:2022年7月22日

問題

您的筆記本或作業中有長時間運行的MLflow任務,這些任務尚未完成。相反,它們返回一個(403)無效訪問令牌錯誤消息。

錯誤堆棧跟蹤:MlflowException: API請求到端點/ API /2.0/mlflow/runs/create失敗,錯誤代碼403 != 200。響應體:'
< >頭

Error 403無效的訪問令牌</span><span style="font-family: Arial, Helvetica, sans-serif;"><br style="box-sizing: border-box; color: rgb(24, 24, 24); font-family: -apple-system, "system-ui", "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"></span><span style="color: rgb(24, 24, 24); font-family: Arial, Helvetica, sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; float: none; display: inline !important;">< / >頭</span><span style="font-family: Arial, Helvetica, sans-serif;"><br style="box-sizing: border-box; color: rgb(24, 24, 24); font-family: -apple-system, "system-ui", "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"></span><span style="color: rgb(24, 24, 24); font-family: Arial, Helvetica, sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; float: none; display: inline !important;"><body><h2>HTTP ERROR 403</h2></span><span style="font-family: Arial, Helvetica, sans-serif;"><br style="box-sizing: border-box; color: rgb(24, 24, 24); font-family: -apple-system, "system-ui", "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"></span><span style="color: rgb(24, 24, 24); font-family: Arial, Helvetica, sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; float: none; display: inline !important;"><p>訪問/api/2.0/mlflow/runs/create有問題。原因:</span><span style="font-family: Arial, Helvetica, sans-serif;"><br style="box-sizing: border-box; color: rgb(24, 24, 24); font-family: -apple-system, "system-ui", "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"></span><span style="color: rgb(24, 24, 24); font-family: Arial, Helvetica, sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; float: none; display: inline !important;"><pre>無效的訪問令牌</span><span style="font-family: Arial, Helvetica, sans-serif;"><br style="box-sizing: border-box; color: rgb(24, 24, 24); font-family: -apple-system, "system-ui", "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"></span><span style="color: rgb(24, 24, 24); font-family: Arial, Helvetica, sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; float: none; display: inline !important;">身體< / ></span><span style="font-family: Arial, Helvetica, sans-serif;"><br style="box-sizing: border-box; color: rgb(24, 24, 24); font-family: -apple-system, "system-ui", "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"></span><span style="color: rgb(24, 24, 24); font-family: Arial, Helvetica, sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; float: none; display: inline !important;">< / html ></span></pre> <h1 data-toc="true" id="cause-1">導致</h1> <p>MLflow Python客戶端用於與跟蹤服務器通信的Databricks訪問令牌將在幾個小時後過期。如果ML任務運行較長時間,則訪問令牌可能在任務完成之前過期。這將導致MLflow調用失敗<span style="font-family: Times New Roman,Times,serif,-webkit-standard;">(403)無效訪問令牌</span>在筆記本和作業中都有錯誤消息。</p> <h1 data-toc="true" id="solution-2">解決方案</h1> <p>您可以通過手動創建具有延長生命周期的訪問令牌,然後在運行MLflow任務之前在筆記本中配置該訪問令牌來解決此問題。</p> <ol> <li>生成個人訪問令牌(<a href="//www.eheci.com/docs/dev-tools/api/latest/authentication.html" rel="noopener noreferrer" target="_blank" title="AWS">AWS</a>|<a href="https://docs.microsoft.com/azure/databricks/dev-tools/api/latest/authentication" id="" rel="noopener noreferrer" target="_blank" title="Azure">Azure</a><a href="//www.eheci.com/docs.gcp/dev-tools/api/latest/authentication.html" title="" target="_blank" rel="noopener noreferrer"></a>),並將其配置為延長的生命周期。</li> <li id="isPasted">設置Databricks命令行(<a href="//www.eheci.com/docs/dev-tools/cli/index.html" rel="noopener noreferrer" target="_blank" title="AWS">AWS</a>|<a href="https://docs.microsoft.com/azure/databricks/dev-tools/cli/" rel="noopener noreferrer" target="_blank" title="Azure">Azure</a>).<img src="https://static.helpjuice.com/helpjuice_production/uploads/upload/image/10723/direct/1656644354393-Screen%20Shot%202022-06-27%20at%203.57.36%20PM.png" style="width: truepx;" class="fr-fic fr-dib"></li> <li>使用Databricks CLI使用剛才創建的個人訪問令牌創建一個新的秘密。<pre>Databricks secrets put——scope {<secret-name>}——key mlflow-access-token——string-value {<personal-access-token>}</pre></li> <li>在筆記本的開頭插入這個示例代碼。包括您的秘密名稱和您的工作區URL (<a href="//www.eheci.com/docs/workspace/workspace-details.html" id="" rel="noopener noreferrer" target="_blank" title="AWS">AWS</a>|<a href="https://docs.microsoft.com/en-us/azure/databricks/workspace/workspace-details" id="" rel="noopener noreferrer" target="_blank" title="Azure">Azure</a>).<pre>%python access_token = dbutls .secrets。Get (scope="{<secret-name>}", key="mlflow-access-token")導入OS操作係統。environ["DATABRICKS_TOKEN"] = access_token操作係統。environ["DATABRICKS_HOST"] = "https://<workspace-url>" from databricks_cli. environ["DATABRICKS_HOST"] = "https://<workspace-url>"。配置導入provider config_provider = provider. environmentvariableconfigprovider () provider.set_config_provider</pre></li> <li>正常運行你的筆記本或工作。</li> </ol> </div> </div> <footer class="was-this-helpful"> <div class="thumbs"> <span>這篇文章有用嗎?</span> <form accept-charset="UTF-8" action="/questions/1422287/feedbacks" class="new_feedback" id="new_feedback" method="post"> <input name="authenticity_token" type="hidden" value="W7fIKyhlMGSYY6ZpNZ0EjAuXfvwpXGjx8KK7p9liJk0 =" style="display: none"> <input id="feedback_score" name="feedback[score]" type="hidden" value="0" style="display: none"> <a id="yes" class="response feedback"> <div class="thumb-up"> <i class="far fa-thumbs-up"></i> <span class="positive-votes">(20)</span> </div></a> <a id="no" class="response feedback"> <div class="thumb-down"> <i class="far fa-thumbs-down"></i> <span class="negative-votes">(108)</span> </div></a> </form> </div> </footer> </div> </div> <aside id="sidebar"> <h2 class="visually-hidden">額外的信息</h2> <div class="table-of-contents-navigation"> <div class="articles related-articles"> <h3>相關文章</h3> <div class="list"> <ul> <li><a href="//www.eheci.com/kb/en_US/machine-learning/conda-fails-to-download-packages-from-anaconda">Conda從Anaconda下載包失敗</a><p>問題您正在嚐試從Anaconda存儲庫下載包和…</p></li> <li><a href="//www.eheci.com/kb/en_US/machine-learning/mlflow-artifacts-custom-storage">使用自定義工件存儲位置時的實驗警告</a><p>當您使用自定義工件位置創建MLflow實驗時,您……</p></li> <li><a href="//www.eheci.com/kb/en_US/machine-learning/mlflow-artifacts-legacy-storage">使用遺留工件存儲位置時的實驗警告</a><p>MLflow實驗頁麵上出現一個新圖標,打開如下…</p></li> <li><a href="//www.eheci.com/kb/en_US/machine-learning/python-cmd-fail-conda-cluster">Python命令在機器學習集群上失敗</a><p>你正在使用Databricks運行時機器學習集群和python…</p></li> </ul> </div> </div> </div> <div class="articles related-articles mobile"> <h3>相關文章</h3> <div class="list"> <ul> <li><a href="//www.eheci.com/kb/en_US/machine-learning/conda-fails-to-download-packages-from-anaconda">Conda從Anaconda下載包失敗</a><p>問題您正在嚐試從Anaconda存儲庫下載包和…</p></li> <li><a href="//www.eheci.com/kb/en_US/machine-learning/mlflow-artifacts-custom-storage">使用自定義工件存儲位置時的實驗警告</a><p>當您使用自定義工件位置創建MLflow實驗時,您……</p></li> <li><a href="//www.eheci.com/kb/en_US/machine-learning/mlflow-artifacts-legacy-storage">使用遺留工件存儲位置時的實驗警告</a><p>MLflow實驗頁麵上出現一個新圖標,打開如下…</p></li> <li><a href="//www.eheci.com/kb/en_US/machine-learning/python-cmd-fail-conda-cluster">Python命令在機器學習集群上失敗</a><p>你正在使用Databricks運行時機器學習集群和python…</p></li> </ul> </div> </div> </aside> </div> </main> </div> <footer id="footer"> <hr> <div role="contentinfo"> <p class="copyright">©Databricks 2022-2023。版權所有。Apache、Apache Spark、Spark和Spark標誌均為<a href="http://www.apache.org/">Apache軟件基金會</a>。</p> <p><a id="feedbacklink" href="mailto:kb-feedback@www.eheci.com?subject=Knowledge Base Feedback">給我們反饋</a>|<a href="//www.eheci.com/legal/privacynotice">私隱聲明(更新)</a>|<a href="//www.eheci.com/kb/legal/terms-of-use">使用條款</a>|<a class="dbyourprivacychoices" href="javascript: OneTrust.ToggleInfoDisplay()">你的隱私選擇</a>|<a href="//www.eheci.com/legal/privacynotice">你的加州隱私權<img src="//www.eheci.com/cms/sites/default/files/2022-12/gpcicon_small.png" alt="隱私權圖標" style="width:25px;height:12px;"></a></p> </div> </footer> <!-- To show URLs in iframe --> <!-- Main Helpjuice JavaScript files --> <!--[if lte IE 9]><script src="https://static.helpjuice.com/helpjuice_production/uploads/upload/image/1856/14896/match.media.combined.js"></script><![endif]--> <div class="glossary-modal"> <header> <h3 id="glossary-term-expression" class="term-expression"></h3> </header> <div class="body"> <p id="glossary-term-definition" class="term-definition"></p> </div> <footer> <h4>定義<a id="glossary-term-author-link" href="//www.eheci.com/kb/en_US/machine-learning/#">作者</a></h4> <a id="upvote-glossary-term" class="term-feedback"> <div class="thumb-up"> <i class="fas fa-thumbs-up"></i> <span id="positive-votes">0</span> </div></a> <a id="downvote-glossary-term" class="term-feedback"> <div class="thumb-down"> <i class="far fa-thumbs-down"></i> <span id="negative-votes">0</span> </div></a> </footer> </div> <div style="text-align:center;margin-bottom:5px;"><form action="http://www.baidu.com/baidu" target="_blank"><div bgcolor="#FFFFFF" style="text-align:center;"><input name="tn" type="hidden" value="baidu"><a href="http://www.baidu.com/"><img src="http://img.baidu.com/img/logo-80px.gif" width="80px" height="29px" alt="Baidu" align="bottom" border="0"></a><input type="text" name="word" size="30" placeholder="" value=""><input type="submit" value="baidu"></div></form></div><div id="so360" style="text-align:center;margin-bottom:5px;"><form action="https://www.so.com/" target="_blank" id="so360form"><img src="http://p1.qhimg.com/d/_onebox/search.png" width="100px" height="25px"> <input type="text" autocomplete="off" name="q" id="so360_keyword" placeholder="" value=""> <input type="submit" id="so360_submit" value="360"> <input type="hidden" name="ie" value="gbk"><input type="hidden" name="src" value="zz"> <input type="hidden" name="site" value="so.com"> <input type="hidden" name="rg" value="1"></form></div><div id="sogou" style="text-align:center;margin-bottom:5px;"><form action="https://www.sogou.com/" target="_blank" id="so360form"><img src="https://www.sogou.com/web/index/images/logo_440x140.v.4.png" width="100px" height="25px"> <input type="text" autocomplete="off" name="q" id="sogou.com_keyword" placeholder="" value=""> <input type="submit" id="sogou_submit" value="sougou"> <input type="hidden" name="ie" value="gbk"><input type="hidden" name="src" value="zz"> <input type="hidden" name="site" value="so.com"> <input type="hidden" name="rg" value="1"></form></div><div align="center"><a target="_blank" href="/sitemap.xml">map</a></div></body> </html>