Spaces:
Sleeping
Sleeping
Download debug_env.py from OctusTech/cartalogo-api: direct link, hf CLI and curl.
- Browser
- Download file 2.33 kB
-
https://huggingface.co/spaces/OctusTech/cartalogo-api/resolve/fef4203a8e525970ba9ea85cd6f4d8d406402c23/debug_env.py
- Command line
-
hf download hf://spaces/OctusTech/cartalogo-api@fef4203a8e525970ba9ea85cd6f4d8d406402c23/debug_env.py
-
curl -L -o debug_env.py https://huggingface.co/spaces/OctusTech/cartalogo-api/resolve/fef4203a8e525970ba9ea85cd6f4d8d406402c23/debug_env.py
2.33 kB
| import os | |
| from pathlib import Path | |
| from dotenv import load_dotenv | |
| def debug_environment(): | |
| """Script para debugar o carregamento das variáveis de ambiente""" | |
| print("🔍 DEBUG: Verificando variáveis de ambiente...") | |
| # Mostra diretório atual | |
| current_dir = Path.cwd() | |
| print(f"📁 Diretório atual: {current_dir}") | |
| # Procura arquivo .env | |
| env_file = current_dir / ".env" | |
| print(f"📄 Arquivo .env: {env_file}") | |
| print(f"📄 Arquivo existe: {env_file.exists()}") | |
| if env_file.exists(): | |
| print(f"📄 Tamanho do arquivo: {env_file.stat().st_size} bytes") | |
| # Lê conteúdo do arquivo | |
| with open(env_file, 'r', encoding='utf-8') as f: | |
| content = f.read() | |
| lines = content.split('\n') | |
| print(f"📄 Linhas no arquivo: {len(lines)}") | |
| # Procura linha da OpenAI | |
| for i, line in enumerate(lines, 1): | |
| if 'OPENAI_API_KEY' in line: | |
| print(f"📄 Linha {i}: {line[:50]}...") | |
| # Tenta carregar .env | |
| print("\n🔄 Carregando .env...") | |
| load_result = load_dotenv(env_file, verbose=True) | |
| print(f"✅ Load result: {load_result}") | |
| # Verifica variáveis após carregar | |
| print("\n🔍 Variáveis após load_dotenv:") | |
| # Lista algumas variáveis importantes | |
| important_vars = [ | |
| 'SUPABASE_URL', | |
| 'SUPABASE_KEY', | |
| 'PINECONE_API_KEY', | |
| 'OPENAI_API_KEY' | |
| ] | |
| for var in important_vars: | |
| value = os.getenv(var) | |
| if value: | |
| if len(value) > 20: | |
| display_value = f"{value[:10]}...{value[-10:]}" | |
| else: | |
| display_value = value[:15] + "..." | |
| print(f" {var}: {display_value}") | |
| else: | |
| print(f" {var}: ❌ NÃO ENCONTRADA") | |
| # Testa carregamento forçado | |
| print("\n🔄 Tentando carregamento forçado...") | |
| # Força reload das variáveis | |
| os.environ.clear() # Limpa variáveis atuais | |
| load_dotenv(env_file, override=True) # Força reload | |
| openai_key = os.getenv('OPENAI_API_KEY') | |
| print(f"🔑 OpenAI após reload: {openai_key[:15] if openai_key else 'NÃO ENCONTRADA'}...") | |
| return openai_key | |
| if __name__ == "__main__": | |
| debug_environment() | |