Spaces:
Sleeping
Sleeping
File size: 3,292 Bytes
611e2c1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
#!/usr/bin/env python3
"""
Quick script to verify your Supabase API key format and connection.
"""
import os
from dotenv import load_dotenv
load_dotenv()
url = os.getenv("SUPABASE_URL")
key = os.getenv("SUPABASE_SERVICE_KEY")
print("=" * 70)
print("Supabase API Key Verification")
print("=" * 70)
print()
if not url:
print("β SUPABASE_URL is not set in .env file")
exit(1)
if not key:
print("β SUPABASE_SERVICE_KEY is not set in .env file")
exit(1)
# Clean the key
key = key.strip()
print(f"π SUPABASE_URL: {url[:30]}...")
print(f"π SUPABASE_SERVICE_KEY: {key[:20]}...{key[-10:] if len(key) > 30 else ''} ({len(key)} chars)")
print()
# Check key format
issues = []
if not key.startswith("eyJ"):
issues.append("β Key doesn't start with 'eyJ' (not a JWT token)")
if len(key) < 100:
issues.append(f"β Key is too short ({len(key)} chars, expected ~200+)")
if len(key) > 500:
issues.append(f"β οΈ Key is unusually long ({len(key)} chars)")
if " " in key or "\n" in key or "\t" in key:
issues.append("β Key contains whitespace (spaces, newlines, tabs)")
if key.startswith('"') or key.endswith('"'):
issues.append("β Key is wrapped in quotes (remove quotes from .env)")
if key.startswith("'") or key.endswith("'"):
issues.append("β Key is wrapped in single quotes (remove quotes from .env)")
if issues:
print("β οΈ Issues found with API key format:")
for issue in issues:
print(f" {issue}")
print()
else:
print("β
Key format looks good!")
print()
# Try to connect
print("π Testing connection to Supabase...")
try:
from supabase import create_client
client = create_client(url, key)
# Try a simple query
try:
client.table("admin_rules").select("id").limit(0).execute()
print("β
Connection successful! API key is valid.")
print()
print("π‘ Next steps:")
print(" 1. Make sure tables exist (run SQL scripts in Supabase)")
print(" 2. Run: python migrate_sqlite_to_supabase.py")
except Exception as e:
error_str = str(e)
if "Invalid API key" in error_str or "401" in error_str:
print("β Connection failed: Invalid API key")
print()
print("π§ How to fix:")
print(" 1. Go to https://app.supabase.com")
print(" 2. Select your project")
print(" 3. Go to Settings β API")
print(" 4. Find 'service_role' key (NOT 'anon' key)")
print(" 5. Click 'Reveal' to show the full key")
print(" 6. Copy the ENTIRE key (it's very long)")
print(" 7. Update SUPABASE_SERVICE_KEY in .env file")
print(" 8. Make sure NO quotes or spaces around the value")
elif "does not exist" in error_str or "relation" in error_str.lower():
print("β οΈ Connection works, but table doesn't exist yet")
print(" This is OK - create tables first, then migrate")
else:
print(f"β Connection error: {error_str}")
except ImportError:
print("β Supabase Python client not installed")
print(" Run: pip install supabase")
except Exception as e:
print(f"β Error: {e}")
print()
print("=" * 70)
|