Databricks Jobs REST API调用不适用于Powershell

问题描述

因此,这是Databricks here

中Jobs API调用链接

一切都可以在Python中使用请求进行。例如,创造就业机会和列出工作都可以

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',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

我也尝试过在这内容上设置Content类型,但是没有帮助。 另外,显式设置代理(提琴手)也无济于事。

-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

或者在RestMethod的情况下

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],Microsoft.PowerShell.Commands.InvokeRestMethodCommand

我本来可以理解在Powershell中是否一切都失败了,但是post方法(创建作业)可以工作,所以不确定,为什么在Get请求而不是post的情况下会终止连接。

浏览一些论坛帖子时,我也尝试了以下操作,但无济于事-

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

有人知道我在做什么错/遗漏吗?困惑地看到在python中工作,但在Powershell中只是一部分。

解决方法

所以,我终于找到了答案。基本上有两件事:

  1. 必须先执行此操作,然后才能到达列表端点(就像我所说的那样-创建端点)

基本允许TLS,TLS1.1和TLS1.2

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls -bor [Net.SecurityProtocolType]::Tls11 -bor [Net.SecurityProtocolType]::Tls12
  1. 仅执行第1点无效。我还不得不使用“高架” PowerShell会话。基本上使用“以管理员身份运行”运行包含步骤1的脚本。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...