使用 python OS 模块配置数据块连接
Configuring databricks-connect using python OS module
我想在通过 os.system("pip install databricks-connect==6.5")
安装 databricks-connect 后通过 python OS 模块配置 databricks-connect configure
成功安装 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")
您可以将数据作为标准输入通过管道传输到程序。
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)
对@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
负责输入
我想在通过 os.system("pip install databricks-connect==6.5")
databricks-connect configure
成功安装 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")
您可以将数据作为标准输入通过管道传输到程序。
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)
对@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
负责输入