0

我想databricks-connect configure在安装databricks-connect之后通过python OS模块进行配置os.system("pip install databricks-connect==6.5")

成功安装 databricks-connect 后,我​​们需要通过传递以下值来配置它:

host= "https://<location>.azuredatabricks.net",
port= "8787",
token = "<Token>",
cluster_id = "<ClusterId>",
org_id = "<OrgId>"

在终端输入databricks-connect configure,会开始一一询问你上面的参数,如图:

在此处输入图像描述

现在我想使用 python os.system 运行同样的东西

os.system("pip install databricks-connect")
os.system("databricks-connect configure")

在此之后如何传递主机、端口、令牌等?
在每个值之后,我们也必须按下enter

当我在终端上运行它时,它工作正常,

echo -e 'https://adb-661130381327abc.11.azuredatabricks.net\nxxxxx\n0529-yyyy-twins608\n6611303813275431\n15001' | databricks-connect configure

但是当我尝试运行这个 python os.module 时给了我错误

os.sytem("echo -e 'https://adb-661130381327abc.11.azuredatabricks.net\nxxxxx\n0529-yyyy-twins608\n6611303813275431\n15001' | databricks-connect configure")

错误“新主机值必须以 https:// 开头,例如 https://demo.cloud.databricks.com”)

4

2 回答 2

1

您可以将数据作为标准输入通过管道传输到程序。

import os


host= "https://<location>.azuredatabricks.net"
port= "8787"
token = "<Token>"
cluster_id = "<ClusterId>"
org_id = "<OrgId>"

stdin_list = [host, port, token, cluster_id, org_id]
stdin_string = '\n'.join(stdin_list)
command = "echo '{}' | {}".format(stdin_string, "databricks-connect configure")
os.system(command)

于 2020-07-25T13:03:38.900 回答
1

对@Anmol 的小修改

import subprocess

host= "https://<location>.azuredatabricks.net"
port= "8787"
token = "<Token>"
cluster_id = "<ClusterId>"
org_id = "<OrgId>"

stdin_list = [host, port, token, cluster_id, org_id]
stdin_string = '\n'.join(stdin_list)
echo = subprocess.Popen((['echo', '-e', stdin_string]), std_out=subprocess.PIPE)
output = subprocess.check_output(('databricks-connect', 'configure'), stdin=echo.stdout)
echo.wait()
print(output.decode())
echo -e

照顾输入

于 2020-07-25T18:08:30.357 回答