webex-bot 1.0.3__py2.py3-none-any.whl → 1.0.4__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
webex_bot/__init__.py CHANGED
@@ -1,4 +1,4 @@
1
1
  """Top-level package for Webex Bot."""
2
2
 
3
3
  __author__ = """Finbarr Brady"""
4
- __version__ = '1.0.3'
4
+ __version__ = '1.0.4'
@@ -276,22 +276,47 @@ class WebexWebsocketClient(object):
276
276
  while True:
277
277
  await _websocket_recv()
278
278
 
279
- try:
280
- asyncio.get_event_loop().run_until_complete(_connect_and_listen())
281
- except InvalidStatusCode as e:
282
- logger.error(f"WebSocket handshake to {ws_url} failed with status {e.status_code}")
283
- if e.status_code == 404:
284
- logger.info("Refreshing WDM device info and retrying...")
285
- self._get_device_info(check_existing=False)
286
- # update ws_url before retry
287
- ws_url = self.device_info.get('webSocketUrl')
279
+ # Track the number of consecutive 404 errors to prevent infinite loops
280
+ max_404_retries = 3
281
+ current_404_retries = 0
282
+
283
+ while True:
284
+ try:
288
285
  asyncio.get_event_loop().run_until_complete(_connect_and_listen())
289
- else:
290
- raise
291
- except Exception as runException:
292
- logger.error(f"runException: {runException}")
293
- if self._get_device_info(check_existing=False) is None:
294
- logger.error('could not create device info')
295
- raise Exception("No WDM device info")
296
- # trigger re-connect
297
- asyncio.get_event_loop().run_until_complete(_connect_and_listen())
286
+ # If we get here, the connection was successful, so break out of the loop
287
+ break
288
+ except InvalidStatusCode as e:
289
+ logger.error(f"WebSocket handshake to {ws_url} failed with status {e.status_code}")
290
+
291
+ if e.status_code == 404:
292
+ current_404_retries += 1
293
+ if current_404_retries >= max_404_retries:
294
+ logger.error(f"Reached maximum retries ({max_404_retries}) for 404 errors. Giving up.")
295
+ raise Exception(f"Unable to connect to WebSocket after {max_404_retries} attempts. Device registration may be invalid.")
296
+
297
+ logger.info(f"Refreshing WDM device info and retrying... (Attempt {current_404_retries} of {max_404_retries})")
298
+ # Force a new device registration
299
+ self._get_device_info(check_existing=False)
300
+ # Update ws_url with the new device info
301
+ ws_url = self.device_info.get('webSocketUrl')
302
+
303
+ # Add a delay before retrying to avoid hammering the server
304
+ logger.info(f"Waiting 5 seconds before retry attempt {current_404_retries}...")
305
+ asyncio.get_event_loop().run_until_complete(asyncio.sleep(5))
306
+ else:
307
+ # For non-404 errors, just raise the exception
308
+ raise
309
+ except Exception as runException:
310
+ logger.error(f"runException: {runException}")
311
+
312
+ # Check if we can get device info
313
+ if self._get_device_info(check_existing=False) is None:
314
+ logger.error('could not create device info')
315
+ raise Exception("No WDM device info")
316
+
317
+ # Update the URL in case it changed
318
+ ws_url = self.device_info.get('webSocketUrl')
319
+
320
+ # Wait a bit before reconnecting
321
+ logger.info("Waiting 5 seconds before attempting to reconnect...")
322
+ asyncio.get_event_loop().run_until_complete(asyncio.sleep(5))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: webex_bot
3
- Version: 1.0.3
3
+ Version: 1.0.4
4
4
  Summary: Python package for a Webex Bot based on websockets.
5
5
  Home-page: https://github.com/fbradyirl/webex_bot
6
6
  Author: Finbarr Brady
@@ -452,6 +452,11 @@ bot = WebexBot(teams_bot_token=os.getenv("WEBEX_ACCESS_TOKEN")
452
452
  * Add connection headers to requests.
453
453
  * Only call me people API once per run.
454
454
 
455
+ ### 1.0.4 (2025-Jul-01)
456
+
457
+ * Add retry mechanism with backoff for websocket 404 errors
458
+ *
459
+
455
460
  [1]: https://github.com/aaugustin/websockets
456
461
 
457
462
  [2]: https://github.com/WebexCommunity/WebexPythonSDK
@@ -1,4 +1,4 @@
1
- webex_bot/__init__.py,sha256=wj46dBgRfdEfusELHz-gJWhMLFfmxqYol-gbZF8c9qY,95
1
+ webex_bot/__init__.py,sha256=Tzm9k-JrR1ZSrXQY5OyBg6ljQWMbUK_6TZJCUgCGfBU,95
2
2
  webex_bot/exceptions.py,sha256=qs9yVitfJtvxwBMC8uCvTDOxUQ_oZjWFf1dU8Oaue14,740
3
3
  webex_bot/formatting.py,sha256=jvPKym-z8CIJygpPVTVbt6vFXQo9_HQHpRDJB-nh-SI,382
4
4
  webex_bot/webex_bot.py,sha256=QRia8QBXnWNt6iwj1kfpcWgPi7RT_DoQfqtdUUbsUTo,21278
@@ -10,9 +10,9 @@ webex_bot/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,
10
10
  webex_bot/models/command.py,sha256=MyThlDaEkGlj1fDE_i_wr79O3QboakimRme8yI744yo,5327
11
11
  webex_bot/models/response.py,sha256=d4k2ohR5SUVzvuQzcnm7jQQVTMB0gH9Kz9y09vkoAaU,2545
12
12
  webex_bot/websockets/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
- webex_bot/websockets/webex_websocket_client.py,sha256=9V5y6yFSoXggaDVjCU6UfQjQKDNLsk6c1vhN8At-2as,12513
14
- webex_bot-1.0.3.dist-info/licenses/LICENSE,sha256=93eGb10xmgkBP2Fh_n0E9YDXe0c0oz-FsnAimXG0S4Y,1072
15
- webex_bot-1.0.3.dist-info/METADATA,sha256=zyqdimzCG4GD9BHKkbnsDkZ9Q6VE_JCWE8-34mt4Dq4,14694
16
- webex_bot-1.0.3.dist-info/WHEEL,sha256=JNWh1Fm1UdwIQV075glCn4MVuCRs0sotJIq-J6rbxCU,109
17
- webex_bot-1.0.3.dist-info/top_level.txt,sha256=q1Y0RtYYinR7oXSwL93cK59c2KN_CbMVca8MLWeF63M,10
18
- webex_bot-1.0.3.dist-info/RECORD,,
13
+ webex_bot/websockets/webex_websocket_client.py,sha256=qVbYquh_FJ-rDZeWspcDydBJOw96U3UcYZSX2XfYYoY,13964
14
+ webex_bot-1.0.4.dist-info/licenses/LICENSE,sha256=93eGb10xmgkBP2Fh_n0E9YDXe0c0oz-FsnAimXG0S4Y,1072
15
+ webex_bot-1.0.4.dist-info/METADATA,sha256=Ni8h1xfMT6ijtlWsucOGK9yqTM2S0GbN3Jw1CAbZFjw,14782
16
+ webex_bot-1.0.4.dist-info/WHEEL,sha256=JNWh1Fm1UdwIQV075glCn4MVuCRs0sotJIq-J6rbxCU,109
17
+ webex_bot-1.0.4.dist-info/top_level.txt,sha256=q1Y0RtYYinR7oXSwL93cK59c2KN_CbMVca8MLWeF63M,10
18
+ webex_bot-1.0.4.dist-info/RECORD,,