4
4
4anlol2019-03-22 22:51:15
Python
4anlol, 2019-03-22 22:51:15

Error with vk api python: "TypeError: 'int' object is not callable" what to do?

There is a mistake in the code, I have already tried everything, maybe you can help

# -*- coding: utf-8 -*-
import vk_api
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
from vk_api.utils import get_random_id
import requests
import time

def main():
       global tel
       global colvo
       vk_session = vk_api.VkApi(
       token='тут токен')
       vk_group = vk_session.get_api()
       longpoll = VkBotLongPoll(vk_session, '179597097')
       for event in longpoll.listen():
              if event.type == VkBotEventType.MESSAGE_NEW:
                     vk_group.messages.send(
                     user_id=event.obj.from_id,
                     random_id=get_random_id(),
                     message=f"Введи номер без +"
                ) 
                     if event.obj.text[0] == "7" and len(event.obj.text) == 11:
                            vk_group.messages.send(
                    user_id=event.obj.from_id,
                    random_id=get_random_id(),
                    message=f"Номер: '{event.obj.text}' принят. Введите количество сообщений (от 2 до 50)")
                            tel = event.obj.text
                            colvo()
                     else:
                                   vk_group.messages.send(
                    user_id=event.obj.from_id,
                    random_id=get_random_id(),
                    message=f"Неверный формат номера"
                )

def sms():
       global tel
       global colvo
       global d
       b = 1
       i = float(1)
       c = float(colvo - 1)
       c = round(c)
       for i in range(colvo):
              print(i)
              time.sleep(2)
              
       if i == c:
              
              vk_session = vk_api.VkApi(
              token='тут токен')
              vk_group = vk_session.get_api()
              longpoll = VkBotLongPoll(vk_session, '179597097')
              vk_group.messages.send(
                    user_id=d,
                    random_id=get_random_id(),
                    message=f"Отлично, мы отправили {colvo} сообщений!")
              print('отправил')
              #main()
              for event in longpoll.listen():
                     if event.obj.text == "exit":
                            main()
            

def colvo():
       global colvo
       global d
       vk_session = vk_api.VkApi(
       token='тут тоже токен')
       vk_group = vk_session.get_api()
       longpoll = VkBotLongPoll(vk_session, '179597097')
       for event in longpoll.listen():
              #if event.type == VkBotEventType.MESSAGE_NEW:
                     if event.obj.text > "1" and event.obj.text < "50":
                            colv = float(event.obj.text)
                            colvo = round(colv)
                            d = event.obj.from_id
                            vk_group.messages.send(
                    user_id=event.obj.from_id,
                    random_id=get_random_id(),
                    message=f"Отлично, мы отправим {colvo} сообщений!"
                )
                            sms()
                     
                     else:
              
                            vk_group.messages.send(
                    user_id=event.obj.from_id,
                    random_id=get_random_id(),
                    message=f"Я не могу обработать больше 50 сообщений"
                )

if __name__ == '__main__':
    main()

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Zagaevsky, 2019-03-22
@4anlol

So here is the call to colvo (), and this is a number. Take it away and that's it.

N
Nikita Kit, 2016-12-14
@ShadowOfCasper

First, it's worth adding AJAX to understand what exactly is wrong. This will load the send script via js after validation (returning a response from the server). By the answer, you can already judge that it does not work. I don't think that without AJAX you can confidently say what the problem is.
And the method is very similar to GET, judging by
"the page is being updated and the string "'?contact=#'" is added to the site address in the address bar.
Perhaps somewhere in the script there is an event listener on submit with preventDefault().

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question