Skip to content

Commit

Permalink
Log detected CF block with no FS setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Casvt committed Jan 22, 2025
1 parent 60476e6 commit 40cb49f
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions backend/implementations/flaresolverr.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from backend.base.definitions import Constants
from backend.base.helpers import Session, Singleton
from backend.base.logging import LOGGER

if TYPE_CHECKING:
from backend.base.helpers import AsyncSession
Expand Down Expand Up @@ -119,16 +120,19 @@ def handle_cf_block(
couldn't solve the problem, or a dictionary with the FlareSolverr
response.
"""
if not (self.session_id and self.base_url):
return

if (
headers.get(Constants.CF_CHALLENGE_HEADER[0])
!= Constants.CF_CHALLENGE_HEADER[1]
):
# Request not failed because of CF block
return

if not (self.session_id and self.base_url):
LOGGER.warning(
"Request blocked by CloudFlare and FlareSolverr not setup"
)
return

with Session() as session:
result = session.post(
self.base_url + self.api_base,
Expand Down Expand Up @@ -168,16 +172,19 @@ async def handle_cf_block_async(
couldn't solve the problem, or a dictionary with the FlareSolverr
response.
"""
if not (self.session_id and self.base_url):
return

if (
headers.get(Constants.CF_CHALLENGE_HEADER[0])
!= Constants.CF_CHALLENGE_HEADER[1]
):
# Request not failed because of CF block
return

if not (self.session_id and self.base_url):
LOGGER.warning(
"Request blocked by CloudFlare and FlareSolverr not setup"
)
return

result = (await (await session.post(
self.base_url + self.api_base,
json={
Expand Down

0 comments on commit 40cb49f

Please sign in to comment.