Skip to content

Commit c7235fe

Browse files
committed
feat(weather): enhance API request with custom headers
Added custom headers to the weather data API request to improve compatibility and prevent caching issues. This change includes a User-Agent string to mimic a browser request, which may help in scenarios where the API restricts access based on client type. The update aims to ensure more reliable data retrieval from the weather service.
1 parent c91f319 commit c7235fe

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/core/widgets/yasb/weather.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,13 @@ def _get_weather_data(self):
155155
def get_weather_data(self, api_url):
156156
logging.info(f"Fetched new weather data at {datetime.now()}")
157157
try:
158-
with urllib.request.urlopen(api_url) as response:
158+
headers = {
159+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:129.0) Gecko/20100101 Firefox/129.0',
160+
'Cache-Control': 'no-cache',
161+
'Referer': 'http://google.com'
162+
}
163+
request = urllib.request.Request(api_url, headers=headers)
164+
with urllib.request.urlopen(request) as response:
159165
weather_data = json.loads(response.read())
160166
current = weather_data['current']
161167
forecast = weather_data['forecast']['forecastday'][0]['day']

0 commit comments

Comments
 (0)