print current html on error

This commit is contained in:
Thephaseless 2024-10-18 14:27:43 +00:00
parent d0b9e7f324
commit 99c90ddc23
3 changed files with 7 additions and 11 deletions

13
main.py
View File

@ -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,

View File

@ -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")

View File

@ -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
]