Open paulocr opened 11 years ago
Are you using master or the 2.4 branch?
I am using 2.4 since I am integrating it with conky
This treats offline as no events instead of throwing errors.
diff --git a/gcalcli/gcalcli.py b/gcalcli/gcalcli.py
index 465a465..d13e494 100755
--- a/gcalcli/gcalcli.py
+++ b/gcalcli/gcalcli.py
@@ -1131,19 +1131,21 @@ class GoogleCalendarInterface:
return eventList
def _search_for_events(self, start, end, search_text):
-
- event_list = []
- for cal in self.cals:
- work = self._cal_service().events().\
- list(calendarId=cal['id'],
- timeMin=start.isoformat() if start else None,
- timeMax=end.isoformat() if end else None,
- q=search_text if search_text else None,
- singleEvents=True)
- events = self._retry_with_backoff(work)
- event_list.extend(self._GetAllEvents(cal, events, end))
-
- event_list.sort(key=lambda x: x['s'])
+ try:
+ event_list = []
+ for cal in self.cals:
+ work = self._cal_service().events().\
+ list(calendarId=cal['id'],
+ timeMin=start.isoformat() if start else None,
+ timeMax=end.isoformat() if end else None,
+ q=search_text if search_text else None,
+ singleEvents=True)
+ events = self._retry_with_backoff(work)
+ event_list.extend(self._GetAllEvents(cal, events, end))
+
+ event_list.sort(key=lambda x: x['s'])
+ except httplib2.ServerNotFoundError:
+ pass
return event_list
For me the error looks like:
Traceback (most recent call last):
File "/home/david/projects/gcalcli/.env/lib/python3.12/site-packages/httplib2/__init__.py", line 1366, in _conn_request
conn.connect()
File "/home/david/projects/gcalcli/.env/lib/python3.12/site-packages/httplib2/__init__.py", line 1142, in connect
address_info = socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/socket.py", line 963, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
socket.gaierror: [Errno -3] Fallo temporal en la resolución del nombre
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/david/projects/gcalcli/.env/bin/gcalcli", line 8, in <module>
sys.exit(main())
^^^^^^
File "/home/david/projects/gcalcli/gcalcli/cli.py", line 230, in main
gcal = GoogleCalendarInterface(
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/david/projects/gcalcli/gcalcli/gcal.py", line 87, in __init__
self._get_cached()
File "/home/david/projects/gcalcli/gcalcli/gcal.py", line 324, in _get_cached
cal_list = self._retry_with_backoff(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/david/projects/gcalcli/gcalcli/gcal.py", line 125, in _retry_with_backoff
return method.execute()
^^^^^^^^^^^^^^^^
File "/home/david/projects/gcalcli/.env/lib/python3.12/site-packages/googleapiclient/_helpers.py", line 130, in positional_wrapper
return wrapped(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/david/projects/gcalcli/.env/lib/python3.12/site-packages/googleapiclient/http.py", line 923, in execute
resp, content = _retry_request(
^^^^^^^^^^^^^^^
File "/home/david/projects/gcalcli/.env/lib/python3.12/site-packages/googleapiclient/http.py", line 222, in _retry_request
raise exception
File "/home/david/projects/gcalcli/.env/lib/python3.12/site-packages/googleapiclient/http.py", line 191, in _retry_request
resp, content = http.request(uri, method, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/david/projects/gcalcli/.env/lib/python3.12/site-packages/google_auth_httplib2.py", line 218, in request
response, content = self.http.request(
^^^^^^^^^^^^^^^^^^
File "/home/david/projects/gcalcli/.env/lib/python3.12/site-packages/httplib2/__init__.py", line 1724, in request
(response, content) = self._request(
^^^^^^^^^^^^^^
File "/home/david/projects/gcalcli/.env/lib/python3.12/site-packages/httplib2/__init__.py", line 1444, in _request
(response, content) = self._conn_request(conn, request_uri, method, body, headers)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/david/projects/gcalcli/.env/lib/python3.12/site-packages/httplib2/__init__.py", line 1373, in _conn_request
raise ServerNotFoundError("Unable to find the server at %s" % conn.host)
httplib2.error.ServerNotFoundError: Unable to find the server at www.googleapis.com
The error doesn't seem that bad to me, but displaying it as an uncaught exception (wrapping another exception) does seem a little ugly. I'd expect instead it should do something like:
$ gcalcli list
Error connecting to server: Unable to find the server at www.googleapis.com
or possibly just
Error connecting to server. Check your internet connection.
Would that suit your case in conky? Completely swallowing the errors and just pretending it got an empty response seems a little too silent/cryptic to me.
Hi insanum,
I wanted to ask if it's possible to improve the handling of error messages. For example when there is no network connection available the error message returned is "Error: [Errno 2] No such file or directory!"
Is it possible to modify this behavior?
I am using gcalcli with conky and when I am not connected I get this error message in my desktop.
Thanks!