Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions vk_api/vk_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import re
import time
import threading

import requests

Expand Down Expand Up @@ -100,10 +101,12 @@ def __init__(self, login=None, password=None, number=None, sec_number=None,
TWOFACTOR_CODE: auth_handler or self.auth_handler
}

self.lock = threading.Lock()

def authorization(self, reauth=False):
""" Полная авторизация с получением токена

:param reauth: Позволяет переавторизиваться, игнорируя сохраненные
:param reauth: Позволяет переавторизиваться, игнорируя сохраненные
куки и токен
"""

Expand Down Expand Up @@ -390,14 +393,15 @@ def method(self, method, values=None, captcha_sid=None, captcha_key=None):
'captcha_key': captcha_key
})

# Ограничение 3 запроса в секунду
delay = DELAY - (time.time() - self.last_request)
with self.lock:
# Ограничение 3 запроса в секунду
delay = DELAY - (time.time() - self.last_request)

if delay > 0:
time.sleep(delay)
if delay > 0:
time.sleep(delay)

response = self.http.post(url, values)
self.last_request = time.time()
response = self.http.post(url, values)
self.last_request = time.time()

if response.ok:
response = response.json()
Expand Down