-
Notifications
You must be signed in to change notification settings - Fork 324
Expand file tree
/
Copy pathproxies_timeout_retries.py
More file actions
36 lines (25 loc) · 893 Bytes
/
proxies_timeout_retries.py
File metadata and controls
36 lines (25 loc) · 893 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# -*- coding: utf-8 -*-
import vk_api
from requests.adapters import HTTPAdapter
class MyHTTPAdapter(HTTPAdapter):
def __init__(self, *args, **kwargs):
self.timeout = kwargs['timeout']
super(MyHTTPAdapter, self).__init__(*args, **kwargs)
def send(self, *args, **kwargs):
kwargs['timeout'] = self.timeout
return super(MyHTTPAdapter, self).send(*args, **kwargs)
def main():
login, password = 'python@vk.ru', 'mypassword'
vk_session = vk_api.VkApi(login, password)
# Proxies:
vk_session.http.proxies = {
'http': 'http://127.0.0.1:8080/',
'https': 'https://127.0.0.1:8080/'
}
# Retries:
vk_session.http.mount('https://', HTTPAdapter(max_retries=10))
# Retries + timeout:
vk_session.http.mount('https://', MyHTTPAdapter(max_retries=10, timeout=8))
# ...
if __name__ == '__main__':
main()