Skip to content

Commit bdc38d2

Browse files
Fix LeetCode submission authentication
1 parent e435a0c commit bdc38d2

1 file changed

Lines changed: 21 additions & 16 deletions

File tree

leetcode/auth.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,31 @@
44

55

66
class LeetCodeAuth:
7-
87
def __init__(self):
98
self.session = Session()
109

11-
self.session.headers.update(
12-
{
13-
"User-Agent": Config.USER_AGENT,
14-
"Referer": "https://leetcode.com/",
15-
"Origin": "https://leetcode.com",
16-
"Content-Type": "application/json",
17-
}
18-
)
10+
self.session.headers.update({
11+
"User-Agent": Config.USER_AGENT,
12+
"Referer": "https://leetcode.com/",
13+
"Origin": "https://leetcode.com",
14+
"Content-Type": "application/json",
15+
"Accept": "application/json",
16+
})
17+
18+
# Authentication cookies
19+
if Config.LEETCODE_SESSION:
20+
self.session.cookies.set(
21+
"LEETCODE_SESSION",
22+
Config.LEETCODE_SESSION,
23+
domain=".leetcode.com"
24+
)
1925

20-
self.session.cookies.update(
21-
{
22-
"LEETCODE_SESSION": Config.LEETCODE_SESSION,
23-
"csrftoken": Config.CSRF_TOKEN,
24-
}
25-
)
26+
if Config.CSRF_TOKEN:
27+
self.session.cookies.set(
28+
"csrftoken",
29+
Config.CSRF_TOKEN,
30+
domain=".leetcode.com"
31+
)
2632

2733
def get_session(self) -> Session:
28-
"""Return the configured session."""
2934
return self.session

0 commit comments

Comments
 (0)