MCPcopy Create free account
hub / github.com/crisxuan/bestJavaer / fetch_remote_image

Function fetch_remote_image

scripts/check_article_quality.py:319–336  ·  view source on GitHub ↗
(url: str, *, timeout: float, method: str)

Source from the content-addressed store, hash-verified

317
318
319def fetch_remote_image(url: str, *, timeout: float, method: str) -> str | None:
320 headers = {
321 "Accept": "image/*,*/*;q=0.8",
322 "User-Agent": "bestjavaer-article-quality/1.0",
323 }
324 if method == "GET":
325 headers["Range"] = "bytes=0-0"
326
327 request = Request(url, headers=headers, method=method)
328 with urlopen(request, timeout=timeout) as response:
329 status = response.getcode()
330 if not 200 <= status < 400:
331 return f"remote image returned HTTP {status}"
332
333 content_type = response.headers.get("Content-Type", "").split(";", 1)[0].lower()
334 if content_type == "text/html":
335 return "remote image returned HTML instead of an image"
336 return None
337
338
339def remote_error_message(error: BaseException) -> str:

Callers 1

request_remote_imageFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected