Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
python: Catch specific exceptions from requests.
Anders Kaseorg7f69c1d3d534
diff --git a/tools/lib/test_server.py b/tools/lib/test_server.pyindex e9be993622d..8ca5e7cb23b 100644--- a/tools/lib/test_server.py+++ b/tools/lib/test_server.py@@ -46,7 +46,7 @@ def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -># We could get a 501 error if the reverse proxy is up but the Django app isn't.# Note that zulipdev.com is mapped via DNS to 127.0.0.1.return requests.get('http://zulipdev.com:9981/accounts/home').status_code == 200- except Exception:+ except requests.RequestException:return False@contextmanagerdiff --git a/zerver/lib/markdown/__init__.py b/zerver/lib/markdown/__init__.pyindex 8b6925ca9d3..ad642916c70 100644--- a/zerver/lib/markdown/__init__.py+++ b/zerver/lib/markdown/__init__.py@@ -449,7 +449,7 @@ def fetch_open_graph_image(url: str) -> Optional[Dict[str, Any]]:# TODO: What if response content is huge? Should we get headers first?try:content = requests.get(url, timeout=1).text- except Exception:+ except requests.RequestException:return None# Extract the head and meta tags# All meta tags are self closing, have no children or are closeddiff --git a/zerver/management/commands/register_server.py b/zerver/management/commands/register_server.pyindex 5979df11f2e..6d94e19d576 100644--- a/zerver/management/commands/register_server.py+++ b/zerver/management/commands/register_server.py@@ -68,14 +68,14 @@ class Command(ZulipBaseCommand):registration_url = settings.PUSH_NOTIFICATION_BOUNCER_URL + "/api/v1/remotes/server/register"try:response = requests.post(registration_url, params=request)- except Exception:+ except requests.RequestException:raise CommandError("Network error connecting to push notifications service "f"({settings.PUSH_NOTIFICATION_BOUNCER_URL})",)try:response.raise_for_status()- except Exception:+ except requests.HTTPError:content_dict = json.loads(response.content.decode("utf-8"))raise CommandError("Error: " + content_dict['msg'])diff --git a/zerver/views/video_calls.py b/zerver/views/video_calls.pyindex 82e76548702..867f5e1e1e0 100644--- a/zerver/views/video_calls.py+++ b/zerver/views/video_calls.py@@ -190,16 +190,16 @@ def join_bigbluebutton(request: HttpRequest, meeting_id: str = REQ(validator=cheif settings.BIG_BLUE_BUTTON_URL is None or settings.BIG_BLUE_BUTTON_SECRET is None:return json_error(_("Big Blue Button is not configured."))else:- response = requests.get(- add_query_to_redirect_url(settings.BIG_BLUE_BUTTON_URL + "api/create", urlencode({- "meetingID": meeting_id,- "moderatorPW": password,- "attendeePW": password + "a",- "checksum": checksum- })))try:+ response = requests.get(+ add_query_to_redirect_url(settings.BIG_BLUE_BUTTON_URL + "api/create", urlencode({+ "meetingID": meeting_id,+ "moderatorPW": password,+ "attendeePW": password + "a",+ "checksum": checksum+ })))response.raise_for_status()- except Exception:+ except requests.RequestException:return json_error(_("Error connecting to the Big Blue Button server."))payload = ElementTree.fromstring(response.text)