Answer the question
In order to leave comments, you need to log in
Why is the connection to the API being reset?
At startup, two threads are launched:
Thread(target=self.input_event).start()
Thread(target=self.read_input).start()
for event in self.long_poll.listen():
if event.type == VkBotEventType.MESSAGE_NEW:
if len(event.object.attachments) > 0:
user_id = event.object.from_id
for pos in range(len(event.object.attachments[0].get('photo').get('sizes'))):
if event.object.attachments[0].get('photo').get('sizes')[pos].get('type', None) == 'w':
img_source = event.object.attachments[0].get('photo').get('sizes')[pos].get('url')
elif event.object.attachments[0].get('photo').get('sizes')[pos].get('type', None) is 'z':
img_source = event.object.attachments[0].get('photo').get('sizes')[pos].get('url')
split_url = img_source
split_url = split_url.split("/")[-1:][0].split(".")[0]
attachments = {'user_id': user_id, 'img_source': img_source, 'split_url': split_url}
logging.info(self.send_message(user_id, 'Отлично! Что вы хотите сделать с изображением?'))
USER_ATTACHMENTS.append(attachments)
logging.info('Received image: ' + str(attachments))
else:
user_id = event.object.from_id
username = self.vk_api.users.get(user_id=user_id)[0]['first_name']
text = event.object.text
data = {'user_id': user_id, 'username': username, 'text': text}
INPUT_EVENTS.append(data)
logging.info('Received message: ' + str(data))
for main_loop in range(len(INPUT_EVENTS)):
if COMMANDS.get(INPUT_EVENTS[main_loop].get('text', None).lower(), None) is not None:
if COMMANDS.get(INPUT_EVENTS[main_loop].get('text', None).lower(), None) == 1:
index_list = main_loop
user_id = INPUT_EVENTS[main_loop].get('user_id', None)
Thread(target=self.command_start, args=(index_list, user_id)).start()
del INPUT_EVENTS[main_loop]
logging.basicConfig(filename="log.log",
level=logging.DEBUG,
format="%(asctime)s:%(levelname)s:%(message)s")
08:28:53,954:DEBUG:https://lp.vk.com:443 "GET /wh119339221?act=a_check&key=KEY&ts=19492&wait=25 HTTP/1.1" 200 381
08:28:53,956:DEBUG:https://lp.vk.com:443 "GET /wh119339221?act=a_check&key=KEY&ts=19492&wait=25 HTTP/1.1" 200 381
08:29:18,966:DEBUG:https://lp.vk.com:443 "GET /wh119339221?act=a_check&key=KEY&ts=19494&wait=25 HTTP/1.1" 200 29
08:29:18,969:DEBUG:https://lp.vk.com:443 "GET /wh119339221?act=a_check&key=KEY&ts=19494&wait=25 HTTP/1.1" 200 29
08:29:18,972:DEBUG:https://lp.vk.com:443 "GET /wh119339221?act=a_check&key=KEY&ts=19494&wait=25 HTTP/1.1" 200 29
08:29:18,974:DEBUG:https://lp.vk.com:443 "GET /wh119339221?act=a_check&key=KEY&ts=19494&wait=25 HTTP/1.1" 200 29
08:29:38,768:DEBUG:https://lp.vk.com:443 "GET /wh119339221?act=a_check&key=KEY&ts=19494&wait=25 HTTP/1.1" 200 148
08:29:38,769:DEBUG:https://lp.vk.com:443 "GET /wh119339221?act=a_check&key=KEY&ts=19494&wait=25 HTTP/1.1" 200 148
08:28:49,852:DEBUG:Resetting dropped connection: lp.vk.com
08:24:27,128:DEBUG:Starting new HTTPS connection (1): pp.userapi.com
try:
...
except requests.exceptions.Timeout as e:
logging.error(e)
os.kill(os.getpid(), signal.SIGINT)
except requests.exceptions.TooManyRedirects as e:
logging.error(e)
os.kill(os.getpid(), signal.SIGINT)
except requests.exceptions.RequestException as e:
Thread(target=self.read_input).join()
logging.error(e)
os.kill(os.getpid(), signal.SIGINT)
2019-05-09 00:20:38,701:WARNING:Connection pool is full, discarding connection:
lp.vk.com .com
Answer the question
In order to leave comments, you need to log in
You understand correctly, daemon threads are terminated together with the main thread. The connection is reset because it has not been used for a long time (this is a setting for VK servers)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question