A
A
Arseniy Kulikov2020-06-05 07:19:55
Python
Arseniy Kulikov, 2020-06-05 07:19:55

Apache+Flask+telebot error?

Apache server. Flask is responsible for webhooks

from flask import Flask, request, redirect
from telebot import types
import requests, json, time
from main import *
from config import *

app = Flask(__name__)

@app.route('/' + BOT_HASH, methods=['POST'])
def webhooks():
    json_string = request.get_data().decode('utf-8')
    update = types.Update.de_json(json_string)
    bot.process_new_updates([update])
    return ''

if __name__ == '__main__':
    app.run()

bot is in main
BOT_HASH in config
Apache log error:

[Fri Jun 05 07:14:03.699910 2020] [wsgi:error] [pid 993:tid 140389314250496] [remote 91.108.6.159:42330] [2020-06-05 07:14:03,699] ERROR in app: Exception on / 1277178986: AAGzs_KXhPMZmQ2k7k5TKorAMBnfjrrbAMo [POST]
[Fri May 7 Close Jun: 14: 03.699936 2020] [wsgi: error] [pid 993: tid 140,389,314,250,496] [remote 91.108.6.159:42330] Traceback (most recent call last):
[Close Jun Fri May 7 :14:03.699941 2020] [wsgi:error] [pid 993:tid 140389314250496] [remote 91.108.6.159:42330] File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/app. py", line 2447, in wsgi_app
[Fri Jun 05 07:14:03.699945 2020] [wsgi:error] [pid 993:tid 140389314250496] [remote 91.108.6.159:42330] response = self.full_dispatch_request()
[Fri Jun 05 07:14:03.699949 2020] [wsgi:error] [pid 993:tid 140389314250496] [remote 91.108.6.159:42330] File "/home/ubuntu/.local/lib/python3.6/site-packages /flask/app.py", line 1952, in full_dispatch_request
[Fri Jun 05 07:14:03.699953 2020] [wsgi:error] [pid 993:tid 140389314250496] [remote 91.108.6.159:42330] rv = self.handle_user_exception( e)
[Fri Jun 05 07:14:03.699957 2020] [wsgi:error] [pid 993:tid 140389314250496] [remote 91.108.6.159:42330] File "/home/ubuntu/.local/lib/python3.6/site -packages/flask/app.py", line 1821, in handle_user_exception
[Fri Jun 05 07:14:03.699961 2020] [wsgi:error] [pid 993:tid 140389314250496] [remote 91.108.6.159:42330] reraise(exc_type, exc_value,tb)
[Fri Jun 05 07:14:03.699965 2020] [wsgi:error] [pid 993:tid 140389314250496] [remote 91.108.6.159:42330] File "/home/ubuntu/.local/lib/python3.6/site-packages /flask/_compat.py", line 39, in reraise
[Fri Jun 05 07:14:03.699969 2020] [wsgi:error] [pid 993:tid 140389314250496] [remote 91.108.6.159:42330] raise value
[Fri Jun 05 07:14:03.699973 2020] [wsgi:error] [pid 993:tid 140389314250496] [remote 91.108.6.159:42330] File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/app .py", line 1950, in full_dispatch_request
[Fri Jun 05 07:14:03.699977 2020] [wsgi:error] [pid 993:tid 140389314250496] [remote 91.108.6.159:42330] rv = self.dispatch_request()
[Fri Jun 05 07:14:03.699981 2020] [wsgi:error] [pid 993:tid 140389314250496] [remote 91.108.6.159:42330] File "/home/ubuntu/.local/lib/python3.6/site-packages /flask/app.py", line 1936, in dispatch_request
[Fri Jun 05 07:14:03.699985 2020] [wsgi:error] [pid 993:tid 140389314250496] [remote 91.108.6.159:42330] return self.view_functions[rule .endpoint](**req.view_args)
[Fri Jun 05 07:14:03.699989 2020] [wsgi:error] [pid 993:tid 140389314250496] [remote 91.108.6.159:42330] File "/home/ubuntu/servicebot/ app.py", line 36, in webhooks
[Fri Jun 05 07:14:03.699993 2020] [wsgi:error] [pid 993:tid 140389314250496] [remote 91.108.6.159:42330] bot.process_new_updates([update])
[Fri Jun 05 07:14:03.699998 2020] [wsgi:error] [pid 993:tid 140389314250496] [remote 91.108.6.159:42330] AttributeError: 'Bot' object has no attribute 'process_new_updates'

The error does not always appear, but only if you do not write anything to the bot for a long time. Perhaps the problem is that the bot instance is imported from another script and "obsoletes" over time, but in any case, tell me, I don't want to catch this error again

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Gleb, 2020-10-15
@Hrafnir

Doesn't the bot knock every time on the webhook address you gave it? What is this Bot_hash in your url?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question