fspv / leetcode-anki

Anki cards generator for Leetcode
MIT License
297 stars 44 forks source link

Error when trying to run `make generate` #39

Open devns8 opened 3 months ago

devns8 commented 3 months ago

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 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. 
fspv commented 3 months ago

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

AlcibiadesCleinias commented 2 months ago

@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
fspv commented 2 months ago

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