Y
Y
y_o_l_k_i_n___e_g_o_r2021-04-13 07:23:18
Python
y_o_l_k_i_n___e_g_o_r, 2021-04-13 07:23:18

Why do endless vk longpoll server requests come?

The code:

import requests

class Bot:
    def __init__(self, token):
        url = f'https://api.vk.com/method/groups.getLongPollServer?group_id=203187908&access_token={token}&v=5.130'
        self.res = requests.get(url).json()['response']
        self.longpoll = f'{self.res["server"]}?act=a_check&key={self.res["key"]}&ts={self.res["ts"]}&wait=25'

    def check(self):
        return requests.get(self.longpoll).json()['updates']


token = 'TOKEN'
vk = Bot(token)
while True:
    print(vk.check())


It sends endless replies from the longpoll server. even with one action, help.
60751d3ac6104943038581.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-04-13
@y_o_l_k_i_n___e_g_o_r

because

ts is the number of the last event, starting from which data should be received;

You installed ts only once, __init__and continue to receive updates on it. Update ts on every request, it comes in this response you get
https://vk.com/dev/using_longpoll

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question