-
Notifications
You must be signed in to change notification settings - Fork 11
Open
Description
Do you happen to have python example?
I've had good success connecting but cant figure out how to query
I'm getting a 401 error
import requests
import hashlib
import hmac
import time
import uuid
import json
sqlRestURL = "http://localhost:5050"
apiKey = bytes('sqlrestTestKey', 'utf-8')
def createHmac(message):
hash = hmac.new(apiKey, message, hashlib.sha256)
return hash.hexdigest()
def setAuthHeader(options, message=bytes('', encoding='utf8')):
realm = "testing-func"
hmac = createHmac(message)
nonce = uuid.uuid4().hex
timestamp = int(round(time.time() * 1000))
options['Authorization'] = f"{realm}:{hmac}:{nonce}:{timestamp}"
return options
def connect():
url = sqlRestURL + "/connect"
options = {}
auth_headers = setAuthHeader(options)
r=requests.get(url, headers=auth_headers)
print(r.status_code)
print(r.json())
def query():
url = sqlRestURL + "/v1/query"
options = {"Content-Type": "application/json"}
payload = {'query': 'SELECT TOP 3 * FROM Flights.dbo.Airlines'}
auth_headers = setAuthHeader(options, bytes(json.dumps(payload), encoding='utf8'))
r=requests.post(url, headers=auth_headers, data=payload)
print(r.status_code)
print(r.json())
Metadata
Metadata
Assignees
Labels
No labels