NicoWeio / blinkist

Tool to download Blinkist's free offerings, namely "Free Daily" and free curated lists
https://nicoweio.github.io/blinkist/
GNU Affero General Public License v3.0
48 stars 12 forks source link

cloudscraper CloudflareChallengeError #35

Open famdude opened 2 months ago

famdude commented 2 months ago

I got this error when tried to get free daily book, so I changed api_request and api_request_web to print session and response:

def api_request(base_url: str, endpoint: str, params=None, **kwargs):
    """
    Wrapper for verifying and retrying GET requests to the Blinkist API.
    Returns the parsed JSON response.
    Calls `request` internally.
    """
    url = base_url + endpoint
    response = request(url, params=params, headers=HEADERS, **kwargs)
    print("RSPONSE")
    print(response)
    return response.json()

def api_request_web(endpoint: str, params=None):
    """
    Wrapper for verifying and retrying GET requests to the Blinkist web API (https://blinkist.com/api/).
    Returns the parsed JSON response.
    """
    print("SESSION COOKOES")
    print(session_cookies)
    return api_request(
        "https://blinkist.com/api/", endpoint, params=params, cookies=session_cookies
    )

but still getting same error. here's the output I get:

SESSION COOKOES
None
⠋ Retrieving free daily in en…[11:56:42] INFO     Retrying in 2.0 seconds…                                                                                  common.py:26
⠼ Retrieving free daily in en…[11:56:46] INFO     Retrying in 2.0 seconds…                                                                                  common.py:26
Traceback (most recent call last):
  File "/path/to/package/blinkist/.venv/lib/python3.10/site-packages/tenacity/__init__.py", line 382, in __call__
    result = fn(*args, **kwargs)
  File "/path/to/package/blinkist/blinkist/common.py", line 41, in request
    raise cloudscraper.exceptions.CloudflareChallengeError()
cloudscraper.exceptions.CloudflareChallengeError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/path/to/package/blinkist/./main.py", line 200, in <module>
    main()
  File "/path/to/package/blinkist/.venv/lib/python3.10/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/path/to/package/blinkist/.venv/lib/python3.10/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/path/to/package/blinkist/.venv/lib/python3.10/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/path/to/package/blinkist/.venv/lib/python3.10/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/path/to/package/blinkist/./main.py", line 150, in main
    book = get_free_daily(locale=language_)
  File "/path/to/package/blinkist/blinkist/blinkist.py", line 18, in get_free_daily
    free_daily = api_request_web('free_daily', params={'locale': locale})
  File "/path/to/package/blinkist/blinkist/common.py", line 67, in api_request_web
    return api_request(
  File "/path/to/package/blinkist/blinkist/common.py", line 54, in api_request
    response = request(url, params=params, headers=HEADERS, **kwargs)
  File "/path/to/package/blinkist/.venv/lib/python3.10/site-packages/tenacity/__init__.py", line 289, in wrapped_f
    return self(f, *args, **kw)
  File "/path/to/package/blinkist/.venv/lib/python3.10/site-packages/tenacity/__init__.py", line 379, in __call__
    do = self.iter(retry_state=retry_state)
  File "/path/to/package/blinkist/.venv/lib/python3.10/site-packages/tenacity/__init__.py", line 326, in iter
    raise retry_exc from fut.exception()
tenacity.RetryError: RetryError[<Future at 0x76af9d056680 state=finished raised CloudflareChallengeError>]
hongthaiphi commented 1 month ago

I have same error: tenacity.RetryError: RetryError[<Future at 0x16f6783b910 state=finished raised CloudflareChallengeError>]