I’m able to connect to Supabase (a postgresql database). However, I keep having issue to retrive data from it.
The error I got is {'message': 'The upstream server is timing out'}
I’m new to supabase. Not sure how to debug this issue.
Here is my code connection.py
import os
import sys
from dotenv import load_dotenv
from supabase import create_client, Client
# Load environment variables
load_dotenv()
# Get Supabase configuration from environment variables
SUPABASE_URL = os.getenv("SUPABASE_URL")
SUPABASE_KEY = os.getenv("SUPABASE_KEY")
SUPABASE_URI = os.getenv("SUPABASE_URI")
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
# Check if environment variables are successfully loaded
if not SUPABASE_URL or not SUPABASE_KEY or not OPENAI_API_KEY or not SUPABASE_URI:
print("Please ensure SUPABASE_URL, SUPABASE_KEY, and OPENAI_API_KEY are correctly set in the .env file.")
sys.exit(1)
else:
print("Connection successful.")
try:
supabase: Client = create_client(SUPABASE_URL, SUPABASE_KEY)
print("Client created successfully.")
except Exception as e:
print("Client creation failed:", e)
sys.exit(1)
# List all table names
try:
response = supabase.table('information_schema.tables').select('table_name').eq('table_schema', 'public').execute()
table_names = [table['table_name'] for table in response.data]
print("All table names:")
for name in table_names:
print(name)
except Exception as e:
print("Connection failed:", e)
sys.exit(1)
Successful: Check if environment variables are successfully loaded
Failed: List all table names
I executed above script from run.sh
as below. It runs connection.py
first. If successful, it will run another python script
# Set environment variables
export OPENAI_API_KEY=""
export SUPABASE_URI=""
export SUPABASE_URL=""
export SUPABASE_KEY=""
# Check Connection
python test_connection.py
# Check the last line was successful
if [ $? -eq 0 ]; then
echo "Connection test passed, starting myapp.py..."
python RAG_app_copy.py
else
echo "Connection test failed, not starting myapp.py."
fi