HrishiKabra commited on
Commit
b735885
·
verified ·
1 Parent(s): 741d068

User-Agent on url fetch

Browse files
Files changed (1) hide show
  1. backend/main.py +3 -1
backend/main.py CHANGED
@@ -63,7 +63,9 @@ async def _read_input(file: Optional[UploadFile], url: Optional[str]) -> tuple[b
63
  if url:
64
  try:
65
  import httpx
66
- async with httpx.AsyncClient(timeout=30, follow_redirects=True) as client:
 
 
67
  r = await client.get(url)
68
  r.raise_for_status()
69
  ct = r.headers.get("content-type", "")
 
63
  if url:
64
  try:
65
  import httpx
66
+ # many image hosts (e.g. Wikimedia) 403 a request without a descriptive UA
67
+ ua = {"User-Agent": "ReefScan/1.0 (+https://github.com/HrishiKabra/reefscan)"}
68
+ async with httpx.AsyncClient(timeout=30, follow_redirects=True, headers=ua) as client:
69
  r = await client.get(url)
70
  r.raise_for_status()
71
  ct = r.headers.get("content-type", "")