aboutsummaryrefslogtreecommitdiffstats
path: root/hyprsunset_qt/sun.py
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-07-17 11:28:26 +0200
committerDanilo M. <danix@danix.xyz>2026-07-17 11:28:26 +0200
commitb2517c9270382794b3ec5be73201590b4127d553 (patch)
treed0df4689f50b5dc435decc26e3aea2f7ffb532f9 /hyprsunset_qt/sun.py
parentade5d98c26da9e0e16685e181377d6c2d5cdf816 (diff)
downloadhyprsunset-qt-b2517c9270382794b3ec5be73201590b4127d553.tar.gz
hyprsunset-qt-b2517c9270382794b3ec5be73201590b4127d553.zip
fix: send User-Agent to avoid Cloudflare 403 on sun API
sunrise-sunset.org sits behind Cloudflare, which rejects the default Python-urllib User-Agent with 403 (error 1010). Send a normal UA in _http_get so fetch_sun and geolocate get through. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'hyprsunset_qt/sun.py')
-rw-r--r--hyprsunset_qt/sun.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/hyprsunset_qt/sun.py b/hyprsunset_qt/sun.py
index aba2ae3..d6b8cd9 100644
--- a/hyprsunset_qt/sun.py
+++ b/hyprsunset_qt/sun.py
@@ -39,9 +39,14 @@ def write_cache(payload: dict, path: Path) -> None:
GEO_URL = "http://ip-api.com/json"
SUN_URL = "https://api.sunrise-sunset.org/json?lat={lat}&lng={lon}&formatted=0"
+# sunrise-sunset.org is behind Cloudflare, which returns 403 (error 1010) for
+# the default Python-urllib User-Agent. Send a normal UA so requests get through.
+_USER_AGENT = "Mozilla/5.0 (X11; Linux x86_64) hyprsunset-qt"
+
def _http_get(url: str, timeout: float = 10.0) -> str:
- with urllib.request.urlopen(url, timeout=timeout) as resp:
+ req = urllib.request.Request(url, headers={"User-Agent": _USER_AGENT})
+ with urllib.request.urlopen(req, timeout=timeout) as resp:
return resp.read().decode()