R
R
RaymanPy2019-02-01 16:17:04
Python
RaymanPy, 2019-02-01 16:17:04

Error processing JSON?

I use WebHook in my TelegramBot
. It has, let's say, a form (name and phone number)

So, when filling in the `name`, an error occurs:

2019-02-01 13:06:42,362: Exception on /`secret` [POST]
Traceback (most recent call last):
  File "/home/PyRayman/venv/lib/python3.6/site-packages/flask/app.py", line 2292, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/PyRayman/venv/lib/python3.6/site-packages/flask/app.py", line 1815, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/PyRayman/venv/lib/python3.6/site-packages/flask/app.py", line 1718, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/PyRayman/venv/lib/python3.6/site-packages/flask/_compat.py", line 35, in reraise
    raise value
  File "/home/PyRayman/venv/lib/python3.6/site-packages/flask/app.py", line 1813, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/PyRayman/venv/lib/python3.6/site-packages/flask/app.py", line 1799, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/PyRayman/TelegramBot/mainbot.py", line 85, in webhook
    bot.process_new_updates([update])
  File "/home/PyRayman/venv/lib/python3.6/site-packages/telebot/__init__.py", line 314, in process_new_updates
    self.process_new_messages(new_messages)
  File "/home/PyRayman/venv/lib/python3.6/site-packages/telebot/__init__.py", line 333, in process_new_messages
    self._notify_next_handlers(new_messages)
  File "/home/PyRayman/venv/lib/python3.6/site-packages/telebot/__init__.py", line 1299, in _notify_next_handlers
    self._exec_task(handler["callback"], message, *handler["args"], **handler["kwargs"])
  File "/home/PyRayman/venv/lib/python3.6/site-packages/telebot/__init__.py", line 464, in _exec_task
    task(*args, **kwargs)
TypeError: 'str' object is not callable

Here is the part of the code where the error occurs:
@app.route('/{}'.format(secret),methods=['POST'])
def webhook():
  print(flask.request.headers)
  if flask.request.headers.get('content-type') == 'application/json':
    json_string = flask.request.get_data().decode('utf-8')
    update = telebot.types.Update.de_json(json_string)
    bot.process_new_updates([update])
    return ''
  else:
      print('You NOT made it!')
      flask.abort(403)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
Y
Yura Khlyan, 2019-02-01
@RaymanPy

Most likely, you named an attribute of a class (most of all task), just like a method of it.

V
Vadim Shatalov, 2019-02-01
@netpastor

Exception on /`secret` [POST]
No error in url?

S
stahh, 2019-02-01
@stahh

Judging by the place where the error occurs in your liseners line(s), but there should be a method(s)
def handle_messages(messages):
for message in messages:
# Do something with the message
bot.reply_to(message, 'Hi')
bot .set_update_listener(handle_messages)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question