Oysiyl commited on
Commit
ac3032e
·
1 Parent(s): d8a05c7

fix: set qrcut upload User-Agent for Cloudflare

Browse files
Files changed (1) hide show
  1. hf_dashboard.py +8 -0
hf_dashboard.py CHANGED
@@ -243,6 +243,8 @@ def _upload_public_png(*, image: Image.Image, object_path: str, max_size: int |
243
  "X-QRCUT-WRITE-KEY": QRCUT_WRITE_API_KEY,
244
  "Content-Type": "image/png",
245
  "X-Upsert": "true",
 
 
246
  },
247
  method="PUT",
248
  )
@@ -256,6 +258,12 @@ def _upload_public_png(*, image: Image.Image, object_path: str, max_size: int |
256
  f"[qrcut] dual-write HTTP {kvm_resp.status}: {object_path} body={response_body}",
257
  flush=True,
258
  )
 
 
 
 
 
 
259
  except (urllib_error.URLError, TimeoutError, OSError) as exc:
260
  print(f"[qrcut] dual-write failed: {exc} -- {object_path}", flush=True)
261
  else:
 
243
  "X-QRCUT-WRITE-KEY": QRCUT_WRITE_API_KEY,
244
  "Content-Type": "image/png",
245
  "X-Upsert": "true",
246
+ "User-Agent": "AI-QR-Code-Generator/1.0 (+https://huggingface.co/spaces/Oysiyl/AI-QR-code-generator)",
247
+ "Accept": "application/json, text/plain, */*",
248
  },
249
  method="PUT",
250
  )
 
258
  f"[qrcut] dual-write HTTP {kvm_resp.status}: {object_path} body={response_body}",
259
  flush=True,
260
  )
261
+ except urllib_error.HTTPError as exc:
262
+ response_body = exc.read(400).decode("utf-8", errors="replace").strip()
263
+ print(
264
+ f"[qrcut] dual-write failed HTTP {exc.code}: {exc.reason} body={response_body} -- {object_path}",
265
+ flush=True,
266
+ )
267
  except (urllib_error.URLError, TimeoutError, OSError) as exc:
268
  print(f"[qrcut] dual-write failed: {exc} -- {object_path}", flush=True)
269
  else: