Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 (api.py): Raise correct error when timeout #45

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions uptime_kuma_api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,13 +500,16 @@ def _get_event_data(self, event) -> Any:
return deepcopy(self._event_data[event].copy())

def _call(self, event, data=None) -> Any:
r = self.sio.call(event, data, timeout=self.timeout)
try:
r = self.sio.call(event, data, timeout=self.timeout)
Copy link
Owner

@lucasheld lucasheld Aug 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The response of self.sio.call is not always a dict (for example api.need_setup). In this case r.pop("ok") fails. You have deleted the code that checks if the response type is a dict.

Also you have deleted the code that checks the r["ok"] value. The UptimeKumaException is now no longer raised when Uptime Kuma responds with an error message (when r["ok"] is false).

except socketio.exceptions.TimeoutError:
raise Timeout(f"Timed out while waiting for event {event}")
if isinstance(r, dict) and "ok" in r:
if not r["ok"]:
raise UptimeKumaException(r.get("msg"))
r.pop("ok")
return r

# event handlers

def _event_connect(self) -> None:
Expand Down