-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathNet.py
More file actions
37 lines (30 loc) · 1.03 KB
/
Net.py
File metadata and controls
37 lines (30 loc) · 1.03 KB
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
37
import requests
import requests.exceptions
HEADER = {'Accept-Encoding': 'identity',
'Connection': 'Keep-Alive',
'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 5.1.1; mi max Build/LMY48Z)'}
class Session:
def __init__(self):
self.session = requests.session()
def new_session(self):
self.session = requests.session()
self.session.keep_alive = False
def get(self, url, **kwargs):
for i in range(5):
try:
r = self.session.get(url=url, **kwargs)
r.close()
return r
except requests.exceptions.ConnectTimeout:
if i == 4:
raise
def post(self, url, data=None, json=None, **kwargs):
for i in range(5):
try:
r = self.session.post(url=url, data=data, json=json, **kwargs)
r.close()
return r
except requests.exceptions.ConnectTimeout:
if i == 4:
raise
session = Session()