CoolFace
Apppublic

OctusTech/cartalogo-api

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
debug_env.py74 linesDownload Raw Back to root
1import os2from pathlib import Path3from dotenv import load_dotenv4 5def debug_environment():6    """Script para debugar o carregamento das variáveis de ambiente"""7    8    print("🔍 DEBUG: Verificando variáveis de ambiente...")9    10    # Mostra diretório atual11    current_dir = Path.cwd()12    print(f"📁 Diretório atual: {current_dir}")13    14    # Procura arquivo .env15    env_file = current_dir / ".env"16    print(f"📄 Arquivo .env: {env_file}")17    print(f"📄 Arquivo existe: {env_file.exists()}")18    19    if env_file.exists():20        print(f"📄 Tamanho do arquivo: {env_file.stat().st_size} bytes")21        22        # Lê conteúdo do arquivo23        with open(env_file, 'r', encoding='utf-8') as f:24            content = f.read()25            lines = content.split('\n')26            print(f"📄 Linhas no arquivo: {len(lines)}")27            28            # Procura linha da OpenAI29            for i, line in enumerate(lines, 1):30                if 'OPENAI_API_KEY' in line:31                    print(f"📄 Linha {i}: {line[:50]}...")32    33    # Tenta carregar .env34    print("\n🔄 Carregando .env...")35    load_result = load_dotenv(env_file, verbose=True)36    print(f"✅ Load result: {load_result}")37    38    # Verifica variáveis após carregar39    print("\n🔍 Variáveis após load_dotenv:")40    41    # Lista algumas variáveis importantes42    important_vars = [43        'SUPABASE_URL',44        'SUPABASE_KEY', 45        'PINECONE_API_KEY',46        'OPENAI_API_KEY'47    ]48    49    for var in important_vars:50        value = os.getenv(var)51        if value:52            if len(value) > 20:53                display_value = f"{value[:10]}...{value[-10:]}"54            else:55                display_value = value[:15] + "..."56            print(f"   {var}: {display_value}")57        else:58            print(f"   {var}: ❌ NÃO ENCONTRADA")59    60    # Testa carregamento forçado61    print("\n🔄 Tentando carregamento forçado...")62    63    # Força reload das variáveis64    os.environ.clear()  # Limpa variáveis atuais65    load_dotenv(env_file, override=True)  # Força reload66    67    openai_key = os.getenv('OPENAI_API_KEY')68    print(f"🔑 OpenAI após reload: {openai_key[:15] if openai_key else 'NÃO ENCONTRADA'}...")69    70    return openai_key71 72if __name__ == "__main__":73    debug_environment()74