Fixed problem with false positives in error 6: Too many requests per second

This commit is contained in:
Manuel Cortez 2016-08-13 20:12:18 -05:00
parent c8927e0b60
commit 4491a600f3

View File

@ -13,7 +13,7 @@ import webbrowser
import logging import logging
import longpoolthread import longpoolthread
import selector import selector
from vk.exceptions import VkAuthError from vk.exceptions import VkAuthError, VkAPIMethodError
from pubsub import pub from pubsub import pub
from mysc.repeating_timer import RepeatingTimer from mysc.repeating_timer import RepeatingTimer
from mysc.thread_utils import call_threaded from mysc.thread_utils import call_threaded
@ -369,7 +369,14 @@ class Controller(object):
log.error("Error in setting online for the current user") log.error("Error in setting online for the current user")
def create_unread_messages(self): def create_unread_messages(self):
msgs = self.session.vk.client.messages.getDialogs(count=50, unread=1) try:
log.debug("Getting possible unread messages.")
msgs = self.session.vk.client.messages.getDialogs(count=200, unread=1)
except VkAPIMethodError as ex:
if ex.code == 6:
log.exception("Something went wrong when getting messages. Waiting a second to retry")
time.sleep(2)
return self.create_unread_messages()
for i in msgs["items"]: for i in msgs["items"]:
wx.CallAfter(self.chat_from_id, i["message"]["user_id"], setfocus=False) wx.CallAfter(self.chat_from_id, i["message"]["user_id"], setfocus=False)
@ -384,7 +391,14 @@ class Controller(object):
response = self.session.vk.client.messages.markAsRead(message_ids=ids) response = self.session.vk.client.messages.markAsRead(message_ids=ids)
def get_audio_albums(self, user_id=None): def get_audio_albums(self, user_id=None):
try:
log.debug("Create audio albums...")
albums = self.session.vk.client.audio.getAlbums(owner_id=user_id) albums = self.session.vk.client.audio.getAlbums(owner_id=user_id)
except VkAPIMethodError as ex:
if ex.code == 6:
log.exception("Something went wrong when getting albums. Waiting a second to retry")
time.sleep(2)
return self.get_audio_albums(user_id=user_id)
self.session.audio_albums = albums["items"] self.session.audio_albums = albums["items"]
for i in albums["items"]: for i in albums["items"]:
buffer = buffers.audioAlbum(parent=self.window.tb, name="{0}_audio_album".format(i["id"],), composefunc="compose_audio", session=self.session, endpoint="get", parent_endpoint="audio", full_list=True, count=self.session.settings["buffers"]["count_for_audio_buffers"], user_id=user_id, album_id=i["id"]) buffer = buffers.audioAlbum(parent=self.window.tb, name="{0}_audio_album".format(i["id"],), composefunc="compose_audio", session=self.session, endpoint="get", parent_endpoint="audio", full_list=True, count=self.session.settings["buffers"]["count_for_audio_buffers"], user_id=user_id, album_id=i["id"])