-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttpManager.py
86 lines (81 loc) · 3.83 KB
/
httpManager.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#Paul Brennan - Requests Manager - Class for dealing with Requests
import requests
import time
import json
from logger import logger
from datetime import datetime
class httpManager:
def __init__(self, debug=False):
self.s = requests.Session()
self.log = logger()
self.debug = debug
self.log.log_message("Initalised a new request session",0)
def debugCheck(self, url, headers=None, proxy=None, response=None, params=None):
if self.debug:
print("URL => ",url)
print("Data => ",params)
print("Headers => ",headers)
print("Proxy => ",proxy)
print("Response Code =>",response.status_code)
for cookie in self.s.cookies:
print("Cookie",cookie)
def getRequest(self, url, headers=None, proxy=None):
#Default config
if headers is None:
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'Accept-Language': 'en-GB',
'Origin': 'https://steamcommunity.com/',
'Referer': 'https://store.steampowered.com',
'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:77.0) Gecko/20100101 Firefox/77.0',
}
try:
response = self.s.get(url, headers=headers, proxies=proxy)
self.debugCheck(url, headers, proxy, response)
if(response.status_code == 200):
self.log.log_message("GET Request to URL ("+url+") responded with status code 200",0)
return(response)
else:
self.log.log_message("GET Request to URL ("+url+") responded with status code ("+str(response.status_code)+")",1)
return(False)
except Exception as e:
self.log.log_message("GET Request to URL ("+url+") responded with a unknown error",1)
if self.debug:
print(e)
return(False)
def postRequest(self, url, params=None, headers=None, proxy=None):
#Default config
if headers is None:
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'Accept-Language': 'en-GB',
'Origin': 'https://steamcommunity.com/',
'Referer': 'https://steamcommunity.com/',
'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:77.0) Gecko/20100101 Firefox/77.0',
}
try:
response = self.s.post(url, params, headers=headers, proxies=proxy)
self.debugCheck(url, headers, proxy, response, params)
if(response.status_code == 200):
self.log.log_message("POST Request to URL ("+url+") with paramaters ("+json.dumps(params)+") responded with status code 200",0)
return(response)
else:
self.log.log_message("POST Request to URL ("+url+") with paramaters ("+json.dumps(params)+") responded with status code ("+str(response.status_code)+")",1)
return(False)
except Exception as e:
self.log.log_message("POST Request to URL ("+url+") with paramaters ("+json.dumps(params)+") responded with a unknown error",1)
if self.debug:
print(e)
return(False)
def verifyProxy(self, proxy):
response = self.getRequest("https://steamcommunity.com/login/home/?goto=")
if(response != False):
if "login" in response.text:
self.log.log_message("Proxy ("+json.dumps(proxy)+") has passed verification",0)
return(True)
else:
self.log.log_message("Proxy ("+json.dumps(proxy)+") has failed verification",1)
return(False)
else:
self.log.log_message("Proxy ("+json.dumps(proxy)+") has failed verification",1)
return(False)