test_notion_token.pyโข1.41 kB
#!/usr/bin/env python3
"""
Simple test script to verify Notion token
"""
import os
from dotenv import load_dotenv
def test_notion_token():
# Load environment
load_dotenv()
# Get token
token = os.getenv("NOTION_API_KEY") or os.getenv("NOTION_TOKEN")
print(f"๐ Token found: {'โ
Yes' if token else 'โ No'}")
if not token:
print("โ No token found in environment variables")
print("๐ก Set NOTION_TOKEN environment variable")
return False
# Test basic connection
try:
from notion_client import Client
print("โ
notion-client imported successfully")
client = Client(auth=token)
print("โ
Client created successfully")
# Test API call
user_info = client.users.me()
print(f"โ
API call successful!")
print(f"๐ง User: {user_info.get('name', 'N/A')} ({user_info.get('id', 'N/A')})")
return True
except ImportError as e:
print(f"โ Import error: {e}")
print("๐ก Run: pip install notion-client")
return False
except Exception as e:
print(f"โ API error: {e}")
print(f"๐ Error type: {type(e).__name__}")
print("๐ก Check your NOTION_TOKEN is valid")
return False
if __name__ == "__main__":
success = test_notion_token()
exit(0 if success else 1)