import urllib.request import json import ssl import time # Config from ak/config.uts SUPA_URL = 'http://192.168.1.61:18000' SUPA_KEY = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiYW5vbiIsImlzcyI6InN1cGFiYXNlLTEiLCJpYXQiOjE3Njk2NzY0OTgsImV4cCI6MTkyNzM1NjQ5OH0.ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890' headers = { "apikey": SUPA_KEY, "Authorization": f"Bearer {SUPA_KEY}", "Content-Type": "application/json" } def get_data(table, query="select=*"): try: url = f"{SUPA_URL}/rest/v1/{table}?{query}" req = urllib.request.Request(url, headers=headers) context = ssl._create_unverified_context() try: with urllib.request.urlopen(req, context=context, timeout=5) as response: if response.status == 200: return json.loads(response.read().decode()) else: return f"Error: {response.status}" except urllib.error.URLError as e: return f"Connection Failed: {e}" except Exception as e: return f"Exception: {e}" print("--- DIAGNOSTIC START ---") # Check ml_user_coupons structure print("\n[ Checking ml_user_coupons Structure ]") # limit=1 to get keys data = get_data("ml_user_coupons", "limit=1") if isinstance(data, list): if len(data) > 0: print("Columns found:", list(data[0].keys())) else: print("Table is empty, cannot infer columns from data.") # Try to insert a dummy record to provoke a schema error? No, that's risky. # Just print that it's empty. else: print(f"Failed to fetch table: {data}") # Check data types if possible (by value) if isinstance(data, list) and len(data) > 0: sample = data[0] print("\nSample Data Types:") for k, v in sample.items(): print(f" {k}: {type(v)} ({v})") print("\n--- DIAGNOSTIC END ---")