130 lines
4.2 KiB
Python
Executable File
130 lines
4.2 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
Debug script to test TickTick authentication in isolation
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
import logging
|
|
from pathlib import Path
|
|
|
|
# Add src to path
|
|
sys.path.insert(0, str(Path(__file__).parent / "src"))
|
|
|
|
# Enable debug logging
|
|
logging.basicConfig(level=logging.DEBUG, format="%(levelname)s: %(message)s")
|
|
|
|
# Set SSL bypass for corporate networks
|
|
os.environ["TICKTICK_DISABLE_SSL_VERIFY"] = "true"
|
|
|
|
# Set your credentials here for testing
|
|
TEST_CLIENT_ID = input("Enter your TICKTICK_CLIENT_ID: ").strip()
|
|
TEST_CLIENT_SECRET = input("Enter your TICKTICK_CLIENT_SECRET: ").strip()
|
|
TEST_USERNAME = input("Enter your TickTick username/email: ").strip()
|
|
|
|
import getpass
|
|
|
|
TEST_PASSWORD = getpass.getpass("Enter your TickTick password: ")
|
|
|
|
if not all([TEST_CLIENT_ID, TEST_CLIENT_SECRET, TEST_USERNAME, TEST_PASSWORD]):
|
|
print("All credentials are required")
|
|
sys.exit(1)
|
|
|
|
os.environ["TICKTICK_CLIENT_ID"] = TEST_CLIENT_ID
|
|
os.environ["TICKTICK_CLIENT_SECRET"] = TEST_CLIENT_SECRET
|
|
|
|
print("\n" + "=" * 60)
|
|
print("TICKTICK DEBUG TEST")
|
|
print("=" * 60)
|
|
|
|
try:
|
|
print("1. Testing OAuth client creation...")
|
|
from services.ticktick.auth import create_oauth_client, get_token_file_path
|
|
|
|
oauth_client = create_oauth_client()
|
|
print(f"✓ OAuth client created")
|
|
print(f"✓ Expected cache path: {get_token_file_path()}")
|
|
|
|
# Check if we have a cached token
|
|
token_file = get_token_file_path()
|
|
print(f"✓ Token file exists: {token_file.exists()}")
|
|
if token_file.exists():
|
|
from services.ticktick.auth import load_stored_tokens
|
|
|
|
tokens = load_stored_tokens()
|
|
if tokens:
|
|
print(
|
|
f"✓ Token loaded, expires: {tokens.get('readable_expire_time', 'Unknown')}"
|
|
)
|
|
else:
|
|
print("⚠ Token file exists but couldn't load")
|
|
|
|
print("\n2. Testing OAuth token retrieval...")
|
|
access_token = oauth_client.get_access_token()
|
|
print(f"✓ Access token retrieved: {access_token[:10]}...{access_token[-10:]}")
|
|
|
|
print("\n3. Testing TickTick client creation...")
|
|
from ticktick.api import TickTickClient
|
|
|
|
# Enable more verbose logging to see HTTP requests
|
|
import urllib3
|
|
|
|
urllib3.disable_warnings()
|
|
|
|
# Monkey patch to get more details about the HTTP response
|
|
original_check_status = TickTickClient.check_status_code
|
|
|
|
def debug_check_status(self, response, error_message):
|
|
print(f"HTTP Response Status: {response.status_code}")
|
|
print(f"HTTP Response Headers: {dict(response.headers)}")
|
|
print(f"HTTP Response Text (first 200 chars): {response.text[:200]}")
|
|
return original_check_status(self, response, error_message)
|
|
|
|
TickTickClient.check_status_code = debug_check_status
|
|
|
|
# This is where the error likely occurs
|
|
print(f"Creating client with username: {TEST_USERNAME}")
|
|
client = TickTickClient(TEST_USERNAME, TEST_PASSWORD, oauth_client)
|
|
print("✓ TickTickClient created successfully!")
|
|
print("\n4. Testing API call...")
|
|
try:
|
|
projects = client.get_by_fields(search="projects")
|
|
print(f"✓ API call successful - found {len(projects)} projects")
|
|
except Exception as api_e:
|
|
print(f"⚠ API call failed: {api_e}")
|
|
|
|
print("\n🎉 ALL TESTS PASSED!")
|
|
|
|
except Exception as e:
|
|
print(f"\n❌ ERROR: {e}")
|
|
print(f"Error type: {type(e).__name__}")
|
|
|
|
import traceback
|
|
|
|
print("\nFull traceback:")
|
|
traceback.print_exc()
|
|
|
|
# Additional debugging
|
|
print("\nDebugging information:")
|
|
print(f"- Python version: {sys.version}")
|
|
print(f"- Working directory: {os.getcwd()}")
|
|
print(f"- Token file path: {get_token_file_path()}")
|
|
|
|
# Check if this is the specific "Could Not Complete Request" error
|
|
if "Could Not Complete Request" in str(e):
|
|
print("""
|
|
This error typically indicates one of:
|
|
1. Incorrect TickTick username/password
|
|
2. Account locked or requires 2FA
|
|
3. Network/SSL issues (even with SSL disabled)
|
|
4. TickTick API changes or service issues
|
|
|
|
Suggestions:
|
|
- Double-check your TickTick login at https://ticktick.com
|
|
- Try a different password (maybe you have special characters?)
|
|
- Check if your account has 2FA enabled
|
|
- Try again later (might be temporary API issue)
|
|
""")
|
|
|
|
print("\n" + "=" * 60)
|