-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstart_server.py
More file actions
73 lines (58 loc) · 2.03 KB
/
start_server.py
File metadata and controls
73 lines (58 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Script de inicialização do servidor API com configuração UTF-8.
Resolve problemas de codificação Unicode no Windows.
"""
import os
import sys
import locale
import subprocess
def setup_encoding():
"""Configurar codificação UTF-8 para evitar erros Unicode."""
# Configurar variáveis de ambiente para UTF-8
os.environ['PYTHONIOENCODING'] = 'utf-8'
os.environ['PYTHONLEGACYWINDOWSFSENCODING'] = '0'
# Configurar locale se possível
try:
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
except locale.Error:
try:
locale.setlocale(locale.LC_ALL, 'C.UTF-8')
except locale.Error:
print("Warning: Could not set UTF-8 locale")
# Configurar stdout/stderr para UTF-8
if hasattr(sys.stdout, 'reconfigure'):
sys.stdout.reconfigure(encoding='utf-8')
sys.stderr.reconfigure(encoding='utf-8')
def main():
"""Função principal para iniciar o servidor."""
print("=== Agentic Real Estate API Server ===")
print("Configuring UTF-8 encoding...")
# Configurar codificação
setup_encoding()
print("Starting server...")
try:
# Importar e executar o servidor
import uvicorn
from api_server import app
# Configuração do servidor
config = {
"app": "api_server:app",
"host": "127.0.0.1",
"port": 8000,
"reload": True,
"log_level": "info",
"access_log": True
}
print(f"Server starting at http://{config['host']}:{config['port']}")
print("Press Ctrl+C to stop the server")
# Iniciar servidor
uvicorn.run(**config)
except KeyboardInterrupt:
print("\nServer stopped by user")
except Exception as e:
print(f"Error starting server: {e}")
sys.exit(1)
if __name__ == "__main__":
main()