From 99c90ddc239770ba975c8aa45d875e9ae2ed3c03 Mon Sep 17 00:00:00 2001 From: Thephaseless Date: Fri, 18 Oct 2024 14:27:43 +0000 Subject: [PATCH] print current html on error --- main.py | 13 +++++-------- src/utils/browser.py | 1 - tests/main_test.py | 4 ++-- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/main.py b/main.py index 7958342..19a9da6 100644 --- a/main.py +++ b/main.py @@ -3,7 +3,6 @@ from __future__ import annotations import asyncio import logging import time -from pathlib import Path import uvicorn import uvicorn.config @@ -39,16 +38,14 @@ async def read_item(request: LinkRequest): timeout = None try: challenged = await asyncio.wait_for(bypass_cloudflare(page), timeout=timeout) - except asyncio.TimeoutError as e: - i = 0 - while Path(f"errors/error{i}.png").is_file(): - i += 1 - await page.save_screenshot(f"errors/error{i}.png") - raise HTTPException(detail="Timeout", status_code=408) from e + except Exception as e: + logger.error(await page.get_content()) + logger.fatal("Element is a string, please report this to Byparr dev") + raise HTTPException(detail="Couldn't bypass", status_code=408) from e logger.info(f"Got webpage: {request.url}") - response = LinkResponse.create( + response = await LinkResponse.create( page=page, start_timestamp=start_time, challenged=challenged, diff --git a/src/utils/browser.py b/src/utils/browser.py index cdb29e6..a01dcee 100644 --- a/src/utils/browser.py +++ b/src/utils/browser.py @@ -81,7 +81,6 @@ async def bypass_cloudflare(page: webdriver.Tab): continue if not isinstance(elem, Element): - logger.fatal("Element is a string, please report this to Byparr dev") raise InvalidElementError elem = await page.find("input") diff --git a/tests/main_test.py b/tests/main_test.py index af17af8..193cb23 100644 --- a/tests/main_test.py +++ b/tests/main_test.py @@ -11,8 +11,8 @@ client = TestClient(app) test_websites = [ "https://ext.to/", "https://btmet.com/", - # "https://extratorrent.st/", # github is blocking these - # "https://idope.se/", # github is blocking these + "https://extratorrent.st/", # github is blocking these + "https://idope.se/", # github is blocking these ]