File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # -*- coding: utf-8 -*-
2+ import vk_api
3+ from requests .adapters import HTTPAdapter
4+
5+
6+ class MyHTTPAdapter (HTTPAdapter ):
7+ def __init__ (self , * args , ** kwargs ):
8+ self .timeout = kwargs ['timeout' ]
9+ super (MyHTTPAdapter , self ).__init__ (* args , ** kwargs )
10+
11+ def send (self , * args , ** kwargs ):
12+ kwargs ['timeout' ] = self .timeout
13+ return super (MyHTTPAdapter , self ).send (* args , ** kwargs )
14+
15+
16+ def main ():
17+ login , password = 'python@vk.com' , 'mypassword'
18+ vk_session = vk_api .VkApi (login , password )
19+
20+ # Proxies:
21+ vk_session .http .proxies = {
22+ 'http' : 'http://127.0.0.1:8080/' ,
23+ 'https' : 'https://127.0.0.1:8080/'
24+ }
25+
26+ # Retries:
27+ vk_session .http .mount ('https://' , HTTPAdapter (max_retries = 10 ))
28+
29+ # Retries + timeout:
30+ vk_session .http .mount ('https://' , MyHTTPAdapter (max_retries = 10 , timeout = 8 ))
31+
32+ # ...
33+
34+ if __name__ == '__main__' :
35+ main ()
You can’t perform that action at this time.
0 commit comments