forked from 4pr0n/CaptureBate
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconnection.py
More file actions
executable file
·60 lines (44 loc) · 1.5 KB
/
Copy pathconnection.py
File metadata and controls
executable file
·60 lines (44 loc) · 1.5 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
'''
Connecting to site
'''
import config
from time import sleep
import requests
from MyAdapter import MyAdapter
# Connects and logs in to to Chaturbate, then returns the logged in requests session
def Connection():
#Connecting to server
count = 0
connected = 0
while connected != 1:
try:
config.logging.info('Connecting to ' + config.URL)
client = requests.session()
client.mount('https://', MyAdapter())
# Retrieve the CSRF token first
request = client.get(config.URL)
connected = 1
except Exception, e:
config.logging.error('Some error during connecting to ' + config.URL)
config.logging.error(e)
config.logging.error('Trying again after 60 seconds')
count += 1
if count > 5:
config.logging.error('Performing delay for 1800 seconds')
sleep(1740)
count = 0
sleep(60)
csrfToken = request.cookies['csrftoken']
# Set login data and perform submit
login_data = dict(username = config.USER, password = config.PASS, csrfmiddlewaretoken=csrfToken, next='/')
try:
request = client.post(config.URL, data = login_data, headers = dict(Referer=config.URL))
except Exception, e:
config.logging.error('Some error during posting to ' + config.URL)
config.logging.error(e)
#config.logging.debug('Page Source for ' + config.URL + '\n' + request.text)
page_source = 'Page Source for ' + config.URL + '\n' + request.text
# if Debugging is enabled Page source goes to debug.log file
if config.Debugging == True:
Store_Debug(page_source, "connection.log")
return client