通过API运行Azure Notebook外部

问题描述

我正在尝试从节点运行笔记本,一切正常,只是笔记本不接受参数,而是根据默认参数发送输出。我没有走错地方。

以下是我的电话:

var job_payload = {
            "run_name": runName,"existing_cluster_id": 'cluster_id',"notebook_task":
            {
                "notebook_path": notebookPath
            },"notebook_params": notebook_params //{'x':1,'y':2}
        }
        
        var url = "https://<location>.<azr_databricks>.net/api/2.0/jobs/runs/submit";
        var options = {
            method: 'POST',headers: {
                'Content-Type': 'application/json','Authorization': 'Bearer token'
            },body: JSON.stringify(job_payload),};

我的笔记本:

import json
dbutils.widgets.text("x",'3',"firstParam")
dbutils.widgets.text("y",'4',"secondParam")
x=int(dbutils.widgets.get("x"))
y=int(dbutils.widgets.get("y"))
sum=x+y
class Output:
  def __init__(self,val):
    self.resultTest2 = val

p1 = Output(sum)
print(p1.resultTest2)
result=json.dumps(p1.__dict__)
#RETURNING THE OUTPUT
dbutils.notebook.exit(result)

我将x:1和y:2作为参数发送,但没有获得输出3,而是获得了7,这是默认值。

由于我没有从文档中获得太多帮助,请提供帮助:

文档URL:Microsoft link

解决方法

我从下面的链接中得到了我错了的答案:

StackOverflow Link

job_payload如下所示:

var job_payload = {
            "run_name": runName,"existing_cluster_id": 'cluster_id',"notebook_task":
            {
                "notebook_path": notebookPath,"base_parameters":notebook_params //{'x':1,'y':2}
            },}
        
        var url = "https://<location>.<azr_databricks>.net/api/2.0/jobs/runs/submit";
        var options = {
            method: 'POST',headers: {
                'Content-Type': 'application/json','Authorization': 'Bearer token'
            },body: JSON.stringify(job_payload),};

现在,它工作正常。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...