Databricks作业REST API调用不适用于Powershell
下面是指向Databricks中的Jobs API调用的链接 在Python中,一切都使用请求。例如,创造就业机会和工作清单都有效Databricks作业REST API调用不适用于Powershell,powershell,databricks,invoke-restmethod,Powershell,Databricks,Invoke Restmethod,下面是指向Databricks中的Jobs API调用的链接 在Python中,一切都使用请求。例如,创造就业机会和工作清单都有效 import requests proxy= "http://127.0.0.1:8888" access_token="tokenabc" proxies = { "https": proxy, } header_read = { 'Authorization': "Bearer &quo
import requests
proxy= "http://127.0.0.1:8888"
access_token="tokenabc"
proxies = {
"https": proxy,
}
header_read = {
'Authorization': "Bearer " + access_token,
'Accept': "application/scim+json"
}
#list jobs
init_get=requests.get('https://databricksworkspaceid.azuredatabricks.net/api/2.0/jobs/list', headers=header_read, proxies=proxies)
#create job
init_post=requests.post('https://databricksworkspaceid.azuredatabricks.net/api/2.0/jobs/create', headers=header_read, proxies=proxies,verify=False,json=job_payload)
然而,奇怪的是,在Powershell中,只有工作创建起作用,而工作列表失败
#this works
Invoke-RestMethod -Uri 'https://databricksworkspaceid.azuredatabricks.net/api/2.0/jobs/create' -Headers @{ 'Authorization' = "Bearer $bearertoken" } -Method Post -Body $content -ContentType 'application/json'
#this does not work
Invoke-WebRequest -Uri 'https://databricksworkspaceid.azuredatabricks.net/api/2.0/jobs/list' -Headers @{ 'Authorization' = "Bearer $bearertoken" } -Method Get
#RestMethod also does not work
Invoke-RestMethod -Uri 'https://databricksworkspaceid.azuredatabricks.net/api/2.0/jobs/list' -Headers @{ 'Authorization' = "Bearer $bearertoken" } -Method Get
我也尝试过在这些上设置内容类型,但没有任何帮助。
此外,显式设置代理(fiddler)也没有帮助
-proxy "http://127.0.0.1:8888"
但也不应该是代理,因为post方法是有效的
我只是不断地犯这样的错误
Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send.
At line:22 char:5
+ Invoke-WebRequest -Uri 'https://databricksworkspaceid.azuredatabricks.net/ap ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
或者在rest方法的情况下
Invoke-RestMethod : The underlying connection was closed: An unexpected error occurred on a send.
At line:22 char:5
+ Invoke-RestMethod -Uri 'https://databricksworkspaceid.azuredatabricks.net/ap ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
如果Powershell中的一切都失败了,我本可以理解,但是post方法(创建工作)可以工作,所以我不确定,为什么会在Get请求而不是post的情况下终止连接
通过一些论坛帖子,我也尝试了以下内容,但没有效果-
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
有人知道我做错了什么/错过了什么吗?在python中工作令人困惑,但它只是Powershell中的一部分。因此,我终于找到了答案。基本上有两件事:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls -bor [Net.SecurityProtocolType]::Tls11 -bor [Net.SecurityProtocolType]::Tls12