leetcode-anki icon indicating copy to clipboard operation
leetcode-anki copied to clipboard

Error when trying to run `make generate`

Open devns8 opened this issue 1 year ago • 3 comments

Hello, I'm on a Mac running Python 3.11.1 and receiving an error when running the make generate build script.

Below is an output from CLI

python3 generate.py /private/tmp/test/leetcode-anki/generate.py:215: DeprecationWarning: There is no current event loop loop: asyncio.events.AbstractEventLoop = asyncio.get_event_loop() Traceback (most recent call last): File "/private/tmp/test/leetcode-anki/generate.py", line 216, in <module> loop.run_until_complete(main()) File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete return future.result() ^^^^^^^^^^^^^^^ File "/private/tmp/test/leetcode-anki/generate.py", line 211, in main await generate(start, stop, page_size, list_id, output_file) File "/private/tmp/test/leetcode-anki/generate.py", line 184, in generate task_handles = await leetcode_data.all_problems_handles() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/private/tmp/test/leetcode-anki/leetcode_anki/helpers/leetcode.py", line 274, in all_problems_handles return list(self._cache.keys()) ^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/functools.py", line 1001, in __get__ val = self.func(instance) ^^^^^^^^^^^^^^^^^^^ File "/private/tmp/test/leetcode-anki/leetcode_anki/helpers/leetcode.py", line 143, in _cache problems = self._get_problems_data() ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/private/tmp/test/leetcode-anki/leetcode_anki/helpers/leetcode.py", line 240, in _get_problems_data problem_count = self._get_problems_count() ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/private/tmp/test/leetcode-anki/leetcode_anki/helpers/leetcode.py", line 76, in wrapper return func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/private/tmp/test/leetcode-anki/leetcode_anki/helpers/leetcode.py", line 148, in _get_problems_count api_instance = self._api_instance ^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/functools.py", line 1001, in __get__ val = self.func(instance) ^^^^^^^^^^^^^^^^^^^ File "/private/tmp/test/leetcode-anki/leetcode_anki/helpers/leetcode.py", line 134, in _api_instance return _get_leetcode_api_client() ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/private/tmp/test/leetcode-anki/leetcode_anki/helpers/leetcode.py", line 38, in _get_leetcode_api_client csrf_token = leetcode.auth.get_csrf_cookie(session_id) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/private/tmp/test/leetcode-anki/leetcode-anki/lib/python3.11/site-packages/leetcode/auth.py", line 12, in get_csrf_cookie return response.cookies["csrftoken"] ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^ File "/private/tmp/test/leetcode-anki/leetcode-anki/lib/python3.11/site-packages/requests/cookies.py", line 334, in __getitem__ return self._find_no_duplicates(name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/private/tmp/test/leetcode-anki/leetcode-anki/lib/python3.11/site-packages/requests/cookies.py", line 413, in _find_no_duplicates raise KeyError(f"name={name!r}, domain={domain!r}, path={path!r}") KeyError: "name='csrftoken', domain=None, path=None" make: *** [generate] Error 1

Any suggestions on how to fix this? I have followed the README steps to a T.

devns8 avatar Jul 18 '24 22:07 devns8

yeah, seems to be broken. Looks like leetcode has changed something on their side. Will take a look if I have time

fspv avatar Jul 19 '24 08:07 fspv

@devns8

so, I kindly resolved the issue, and additionally by providing a new feature. But, as the new feature is optional, you could just use the code with the provided flow in README.md (the new manual work added: you need to manually get CRSF TOKEN from cookie, screenshot also added)

git clone -b alcibiadesCleinias/fetch-user-submission https://github.com/AlcibiadesCleinias/leetcode-anki.git

AlcibiadesCleinias avatar Jul 24 '24 16:07 AlcibiadesCleinias

Hi @AlcibiadesCleinias. Thanks for working on that and your PR! I need to look at it a bit closer, but don't have time at the moment. I'll try to do so in the next few days.

At the first glance it looks ok, but I'm not completely convinced about including more data to the card. I mean we can include anything there but uncontrolled inclusion of everything will eventually lead to a complex logic with a lot of branching based on the feature flags.

Anyway, one thing I know for sure is that we need to split your PR into two:

  1. Fix of the CSRF token issue
  2. This experimental feature

It will be much easier to assess those changes independently.

I think I also need to actually remove this csrf method from the python-leetcode lib, because it is not working, but this is another issue

fspv avatar Jul 24 '24 21:07 fspv

Thank you so much! Your pull request works for me!

kunleihe avatar Nov 11 '24 08:11 kunleihe

This doesn't seem to solve the issue for me. Still throwing an error:

File "/private/tmp/leetcode-anki/leetcode-anki/lib/python3.11/site-packages/requests/cookies.py", line 413, in _find_no_duplicates raise KeyError(f"name={name!r}, domain={domain!r}, path={path!r}") KeyError: "name='csrftoken', domain=None, path=None" make: *** [generate] Error 1

devns8 avatar Feb 25 '25 20:02 devns8

Hey, sorry I keep forgetting about this repo. Just fixed the issue and updated the readme with the new instructions. Basically you need to set one more env variable and put a csrf token from the cookie there.

Should be working now. Also you can find the latest generated desk here: https://github.com/fspv/leetcode-anki/releases/tag/2025-02-26

fspv avatar Feb 26 '25 22:02 fspv