write agent.py

This commit is contained in:
a2a-cloud
2026-06-07 23:15:50 +00:00
parent 5f7dd57c2b
commit d79395521c

View File

@@ -280,7 +280,7 @@ def _robots_allowed(url: str, user_agent: str) -> dict[str, Any]:
urllib.request.Request(robots_url, headers={"User-Agent": user_agent}), urllib.request.Request(robots_url, headers={"User-Agent": user_agent}),
timeout=10, timeout=10,
) as response: ) as response:
body = response.read(2_000_000).decode("utf-8", errors="ignore") body = response.read(2000000).decode("utf-8", errors="ignore")
rp.parse(body.splitlines()) rp.parse(body.splitlines())
return {"allowed": bool(rp.can_fetch(user_agent, url)), "robots_url": robots_url, "warnings": []} return {"allowed": bool(rp.can_fetch(user_agent, url)), "robots_url": robots_url, "warnings": []}
except urllib.error.HTTPError as exc: except urllib.error.HTTPError as exc:
@@ -349,7 +349,7 @@ def _render_scraper_script(payload: dict[str, Any]) -> str:
try: try:
req = urllib.request.Request(robots_url, headers={{"User-Agent": user_agent}}) req = urllib.request.Request(robots_url, headers={{"User-Agent": user_agent}})
with urllib.request.urlopen(req, timeout=10) as response: with urllib.request.urlopen(req, timeout=10) as response:
body = response.read(2_000_000).decode("utf-8", errors="ignore") body = response.read(2000000).decode("utf-8", errors="ignore")
rp.parse(body.splitlines()) rp.parse(body.splitlines())
return bool(rp.can_fetch(user_agent, url)), None return bool(rp.can_fetch(user_agent, url)), None
except Exception as exc: except Exception as exc: