-
-
Notifications
You must be signed in to change notification settings - Fork 46
Open
Description
Checklist
- I am sure the error is coming from Hydrogram's code and not elsewhere
- I have searched in the issue tracker for similar bug reports, including closed ones
- I ran
pip3 install -U https://github.com/hydrogram/hydrogram/archive/dev.zipand reproduced the issue using the latest development version
Description
The Hydrogram bot does not connect to Telegram in any way and does not report any error.Unless you enable logging in debug mode, it's possible to find the error. Otherwise, Hydrogram does not report the error, and the bot is not started.
Solution:
sudo date -s "$(curl -s --head http://google.com | grep ^Date: | sed 's/Date: //g')"
Steps to reproduce
To reproduce the error, simply have your server's time out of sync with Telegram. When trying to connect using Hydrogram, no error is reported, leaving the user unable to understand why it doesn't connect.
Code example
import os
import logging
from hydrogram import Client, filters
# Configurar logs detalhados
logging.basicConfig(
level=logging.DEBUG,
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
handlers=[
logging.StreamHandler(), # Exibe logs no console
logging.FileHandler("debug.log", encoding="utf-8") # Salva logs em arquivo
]
)
# Configurando as variáveis de ambiente diretamente (substitua pelos seus valores reais)
API_ID = os.getenv("API_ID", 123456) # Substitua pelo seu API_ID
API_HASH = os.getenv("API_HASH", "abc123def456") # Substitua pelo seu API_HASH
BOT_TOKEN = os.getenv("BOT_TOKEN", "seu_bot_token_aqui") # Substitua pelo seu BOT_TOKEN
logging.debug("Configurando o cliente...")
try:
app = Client(
name="my_bot",
api_id=API_ID,
api_hash=API_HASH,
bot_token=BOT_TOKEN,
)
logging.info("Cliente configurado com sucesso.")
except Exception as e:
logging.critical(f"Erro ao configurar o cliente: {e}")
raise
# Função simples para responder mensagens privadas
@app.on_message(filters.private)
async def hello(client, message):
logging.debug(f"Recebeu uma mensagem: {message.text}")
await message.reply("Hello from Hydrogram!")
# Executar o cliente
logging.debug("Iniciando o cliente...")
try:
app.run()
except Exception as e:
logging.critical(f"Erro crítico ao executar o cliente: {e}")Logs
2025-04-05 11:22:34,653 - hydrogram.session.session - INFO - Discarding packet: The msg_id belongs to over 30 seconds in the future. Most likely the client time has to be synchronized.
2025-04-05 11:22:34,653 - hydrogram.session.session - INFO - NetworkTask stopped
2025-04-05 11:22:34,653 - hydrogram.connection.connection - INFO - DisconnectedMetadata
Metadata
Assignees
Labels
No labels