Add User-Agent#8
Conversation
There was a problem hiding this comment.
Pull request overview
Adds an explicit HTTP User-Agent header when fetching Meteoclimatic station RSS feeds.
Changes:
- Switches
urlopen(url)tourlopen(Request(...))to include aUser-Agentheader. - Minor formatting adjustments around the raised
MeteoclimaticError.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def weather_at_station(self, station_code): | ||
| url = self._base_url.format(station_code=station_code) | ||
|
|
||
| req = Request(url, headers={"User-Agent": "HomeAssistant Meteoclimatic"}) |
There was a problem hiding this comment.
The hard-coded User-Agent value references "HomeAssistant", but this library is published as "pymeteoclimatic" and is not Home Assistant-specific (see README.md / setup.py). Consider using a library-identifying UA string (e.g., package name + version) and/or making the User-Agent configurable via the client constructor so downstream consumers can set their own UA.
| def weather_at_station(self, station_code): | |
| url = self._base_url.format(station_code=station_code) | |
| req = Request(url, headers={"User-Agent": "HomeAssistant Meteoclimatic"}) | |
| def __init__(self, user_agent: str | None = None) -> None: | |
| """Initialize the Meteoclimatic client. | |
| Args: | |
| user_agent: Optional User-Agent string to use for HTTP requests. | |
| If not provided, a default identifying this library is used. | |
| """ | |
| self._user_agent = user_agent or "pymeteoclimatic" | |
| def weather_at_station(self, station_code): | |
| url = self._base_url.format(station_code=station_code) | |
| req = Request(url, headers={"User-Agent": self._user_agent}) |
There was a problem hiding this comment.
Agree with this comment. Even though this library is used in Home Assistant's Meteoclimatic integration, it can also be used on its own or from any other platform.
It'd use pymeteoclimatic/<version>.
adrianmo
left a comment
There was a problem hiding this comment.
Thanks for the PR. Can we also add/update test cases to make sure the changes are covered? Thanks
|
I've tried to test it, but being in the core I haven't had much time. |
|
The problem, in principle, is that Meteoclimatic has blocked access. |
No description provided.