I'm using Dremio Rest API in python, below is part of my code which is running fine for me. In the print data statement, I'm able to see my userid, email etc which indicates that code is running fine upto this point.
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)
This is the part where I am running into an error. Error message is following (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)