-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmindsdb_utils.py
More file actions
23 lines (20 loc) · 776 Bytes
/
Copy pathmindsdb_utils.py
File metadata and controls
23 lines (20 loc) · 776 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import os
import requests
from dotenv import load_dotenv
load_dotenv()
MINDSDB_API_URL = f"{os.environ.get('MINDSDB_HOST')}:{os.environ.get('MINDSDB_TCP_PORT')}/api"
MINDSDB_USER = os.environ.get("MINDSDB_USER")
MINDSDB_PASSWORD = os.environ.get("MINDSDB_PASSWORD")
def query_mindsdb(query):
headers = {"Content-Type": "application/json"}
auth = (MINDSDB_USER, MINDSDB_PASSWORD)
data = {"query": query}
try:
response = requests.post(f"{MINDSDB_API_URL}/sql/query", headers=headers, auth=auth, json=data)
response.raise_for_status()
return response.json()
except requests.exceptions.RequestException as e:
print(f"Error querying MindsDB: {e}")
if e.response:
print(e.response.text)
return None