Closed shuaiwang2022 closed 9 months ago
This happens when the LeetCode server finds your cookie invalid.
Here are some common reasons:
leetcode.com
but for parallel websites like leetcode.cn
This is how I obtained mine.
leetcode.com
Notice that the leetcode OJ environment is not compatible with
leetcode.cn
Just to let you know, you must have your account verified by e-mail before you use it.
For example, if you are using Chrome, this will be
View
>Developer
>Developer Tools
.
Go to
Storage
>Cookies
>leetcode.com
.Copy the
LEETCODE_SESSION
entry. It should look like a long long string aseyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJfYXV0aF91c2VyX2lkIjoiMTEyNzM3OTYiLCJfYXV0aF91c2VyX2JhY2tlbmQiOiJkamFuZ28uY29udHJpYi5hdXRoLmJhY2tlbmRzLk1vZG......
It is OK if you close the web page. But manually logging out or switching accounts makes your cookie invalid.
If you really want to switch accounts, you may use the anonymous mode of your browser to get the cookie and close the page after that.
I closed the issue for now since I think my reply should resolve your problem. Welcome to re-open it if you have more issues.
I had the same error today, I've tried all the steps and still can't fix it
I had the same error today, I've tried all the steps and still can't fix it
I have tested the code today and it works well for me when the cookie is correct.
So from my perspectives, it is likely that you are getting an improper cookie.
Please leave your e-mail so that I can send you the cookie I use. You can try that out. If this cookie also works well for you, the code of this repository should be flawless.
I had the same error today, I've tried all the steps and still can't fix it
If this problem continually bothers you, we can have a brief zoom meeting to solve it if you like :)
I had the same error today, I've tried all the steps and still can't fix it
If this problem continually bothers you, we can have a brief zoom meeting to solve it if you like :)
I had the similar error, I follow your step and I think my cookie is right. Do you have time to test the code again? Maybe leetcode has changed something.
@xuhaolei Hi, I have udpated leetcode_oj module. Now we should pass BOTH leetcode_session
and csrf_token
to the LeetCodeTester
like this
leetcode_session = os.environ['LEETCODE_SESSION']
csrf_token = os.environ['CSRF_TOKEN']
class LeetCodeTester(object):
def __init__(self, leetcode_session: str=None, csrf_token: str=None, cooldown: int=10):
self.env = LeetCodeEnv(cooldown=cooldown, leetcode_session=leetcode_session, csrf_token=csrf_token)
self.lang_dict = {
"python": ProgrammingLanguage.PYTHON3,
"python3": ProgrammingLanguage.PYTHON3,
"java": ProgrammingLanguage.JAVA,
"c": ProgrammingLanguage.C,
"cpp": ProgrammingLanguage.CPP,
}
def test(self, code: str, task_id: str, language: str) -> tuple[bool, dict]:
lang = self.lang_dict.get(language)
sub = LeetCodeSubmission(code=code, lang=lang, question_slug=task_id)
status, reward, done, submission_result = self.env.step(sub)
return reward, submission_result
if __name__ == '__main__':
tester = LeetCodeTester(leetcode_session=leetcode_session, csrf_token=csrf_token, cooldown=10)
task_id = TEST_CASE['task_id']
code0 = TEST_CASE['original_code']
code1 = TEST_CASE['problematic_code']
codes = [code0, code1]
for code in codes:
print(tester.test(code, task_id, "python"))
And this should work. Please inform me if you need more help.
@xuhaolei Please e-mail me at runchutian@gmail.com if you need further assistance like zoom meeting or something.
@Rachum-thu I followed your steps, but I encountered a similar error. Do you have time to test the code again? I