Python 中的 Dremio Rest API - 连接中止错误

Dremio Rest API in Python - Connection Abort Error

提问人:Hello World 提问时间:4/13/2023 更新时间:4/13/2023 访问量:145

问:

我在 python 中使用 Dremio Rest API,以下是我的代码的一部分,对我来说运行良好。在打印数据语句中,我能够看到我的用户 ID、电子邮件等,这表明到目前为止代码运行良好。

import json
import requests

username = 'myusername'
password = 'mypassword'
headers = {'content-type':'application/json'}
dremioServer = 'https://myserver/apiv2'

def apiGet(endpoint):
  return json.loads(requests.get('{server}/apiv2/{endpoint}'.format(server=dremioServer, endpoint=endpoint), headers=headers).text)
   
def apiPost(endpoint, body=None):
  text = requests.post('{server}/apiv2/{endpoint}'.format(server=dremioServer, endpoint=endpoint), headers=headers, data=json.dumps(body)).text


  if (text):
    return json.loads(text)
  else:
    return None

def apiPut(endpoint, body=None):
  return requests.put('{server}/apiv2/{endpoint}'.format(server=dremioServer, endpoint=endpoint), headers=headers, data=json.dumps(body)).text

def apiDelete(endpoint):
  return requests.delete('{server}/apiv2/{endpoint}'.format(server=dremioServer, endpoint=endpoint), headers=headers)

def login(username, password):
  loginData = {'userName': username, 'password': password}
  response = requests.post('https://myserver/apiv2/login', headers=headers, data=json.dumps(loginData))
  data = json.loads(response.text)
  print(data)
  token = data['token']
  return {'content-type':'application/json', 'authorization':'_ dremio{authToken}'.format(authToken=token)}

headers = login(username, password)

这是我遇到错误的部分。错误消息如下 (ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response')))

def querySQL(query):
  queryResponse = apiPost('sql', body={'sql': query})
  jobid = queryResponse['id']
  return jobid

path = ['\"@elbert\"', 'wta', 'matches']
path = '.'.join([str(x) for x in path])
query = '''SELECT * FROM "wta"."matches"'''.format(source=path)
jobid = querySQL(query)
Python API REST 德雷米奥

评论


答: 暂无答案