Answer the question
In order to leave comments, you need to log in
How to use django orm in telegram bot?
I have a bot written in the PyTelegramBotAPI library, in which I use django ORM. I used to get the MySQL Server has gone away error, I increased MAX_CONNECTION and now the bot just stops working without throwing any errors.
Answer the question
In order to leave comments, you need to log in
Although the question was asked a long time ago, but I also encountered this problem.
tldr:
bot needs to be initialized bot = telebot.TeleBot(TOKEN, threaded=False)
long version:
The fact is that by default the telebot starts up with the ability to run multiple threads for each event handler. In the case of django and webhooks, this is done like this:
@csrf_exempt
def bot_view(request):
if request.method != 'POST':
return HttpResponse(status=403)
if request.META.get('CONTENT_TYPE') != 'application/json':
return HttpResponse(status=403)
json_string = request.body.decode('utf-8')
update = telebot.types.Update.de_json(json_string)
bot.process_new_updates([update])
return HttpResponse(status=200)
@bot.message_handler(commands=['start'])
def start(message):
user = message.chat.id
...обработка
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question