Skip to content

Commit a810e37

Browse files
committed
used send_request helpers methods
1 parent 4b7f187 commit a810e37

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

src/helpers.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ def send_request(
1010
method: str = "GET",
1111
json: dict[str, Any] = {},
1212
headers: dict[str, str] = {},
13+
data: dict[str, Any] = {},
1314
) -> Response:
1415
try:
15-
resp = send_request_helper(session, url, method, json, headers)
16+
resp = send_request_helper(session, url, method, json, headers, data)
1617
resp.raise_for_status()
1718
except Exception as ex:
1819
retries = 10
1920
for _ in range(retries):
2021
try:
21-
resp = send_request_helper(session, url, method, json, headers)
22+
resp = send_request_helper(session, url, method, json, headers, data)
2223
resp.raise_for_status()
2324
except Exception as inner_ex:
2425
if (
@@ -51,12 +52,13 @@ def send_request_helper(
5152
method: str,
5253
json: dict[str, Any],
5354
headers: dict[str, str],
55+
data: dict[str, Any],
5456
) -> Response:
5557
timeout = 2
5658
if method == "GET":
5759
resp = session.get(url, headers=headers, timeout=timeout)
5860
elif method == "POST":
59-
resp = session.post(url, json=json, headers=headers, timeout=timeout)
61+
resp = session.post(url, json=json, data=data, headers=headers, timeout=timeout)
6062
else:
6163
raise Exception("Invalid method: {}".format(method))
6264
return resp

src/login.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
from requests import Session
22
from bs4 import BeautifulSoup, Tag
33
import re
4+
from typing import Any
45

56
import config
67
import totp
8+
from helpers import send_request
79

810

911
def login_with_drexel_connect(session: Session) -> Session:
10-
response = session.get(config.drexel_connect_base_url)
12+
response = send_request(session, config.drexel_connect_base_url, method="GET")
1113
soup = BeautifulSoup(response.text, "html.parser")
1214

1315
csrf_token = extract_csrf_token(soup)
@@ -21,26 +23,20 @@ def login_with_drexel_connect(session: Session) -> Session:
2123
}
2224

2325
# this should send the credentials and send the MFA request
24-
response = session.post(
25-
config.drexel_connect_base_url + form_action_path, data=login_payload
26-
)
26+
response = send_request(session, config.drexel_connect_base_url + form_action_path, data=login_payload, method="POST")
2727

2828
soup = BeautifulSoup(response.text, "html.parser")
2929
data = parse_initial_mfa_page(soup)
3030

31-
response = session.post(
32-
config.drexel_connect_base_url + data["url"], data=data["form-data"]
33-
)
31+
response = send_request(session, config.drexel_connect_base_url + data["url"], data=data["form-data"], method="POST")
3432
json_response = response.json()
3533

3634
data = {
3735
json_response["csrfN"]: json_response["csrfV"],
3836
"_eventId": json_response["actValue"],
3937
}
4038

41-
response = session.post(
42-
config.drexel_connect_base_url + json_response["flowExURL"], data=data
43-
)
39+
response = send_request(session, config.drexel_connect_base_url + json_response["flowExURL"], data=data, method="POST")
4440
soup = BeautifulSoup(response.text, "html.parser")
4541

4642
parsed_data = parse_final_mfa_page(soup)
@@ -53,10 +49,10 @@ def login_with_drexel_connect(session: Session) -> Session:
5349
"j_mfaToken": totp_code,
5450
}
5551

56-
response = session.post(
57-
config.drexel_connect_base_url + parsed_data["url"], data=data
58-
)
59-
52+
# session.post(
53+
# config.drexel_connect_base_url + parsed_data["url"], data=data
54+
# )
55+
send_request(session, config.drexel_connect_base_url + parsed_data["url"], data=data, method="POST")
6056
return session
6157

6258

@@ -98,7 +94,7 @@ def extract_form_action_path(soup: BeautifulSoup) -> str:
9894
return form_action_path
9995

10096

101-
def parse_initial_mfa_page(soup: BeautifulSoup) -> dict[str, str]:
97+
def parse_initial_mfa_page(soup: BeautifulSoup) -> dict[str, Any]:
10298
data = {}
10399

104100
# get the first script tag that isn't empty

0 commit comments

Comments
 (0)