mirror of https://github.com/zulip/zulip.git
markdown: Catch urllib3 exceptions which are raised during streaming.
requests transforms the base urllib3 exceptions into requests.RequestExceptions -- but only within code that it is running. When parsing the streaming body in fetch_open_graph_image, the read itself (inside lxml) may trigger urllib3 to raise its own timeout error -- which escapes the current catch of requests.RequestExceptions. Catch both requests and urllib3 exceptions.
This commit is contained in:
parent
c98bf184bb
commit
b7bf9e41c7
|
@ -44,6 +44,7 @@ import re2
|
|||
import regex
|
||||
import requests
|
||||
import uri_template
|
||||
import urllib3.exceptions
|
||||
from django.conf import settings
|
||||
from markdown.blockparser import BlockParser
|
||||
from markdown.extensions import codehilite, nl2br, sane_lists, tables
|
||||
|
@ -474,7 +475,7 @@ def fetch_open_graph_image(url: str) -> Optional[Dict[str, Any]]:
|
|||
elif element.get("property") == "og:description":
|
||||
og["desc"] = element.get("content")
|
||||
|
||||
except requests.RequestException:
|
||||
except (requests.RequestException, urllib3.exceptions.HTTPError):
|
||||
return None
|
||||
|
||||
return None if og["image"] is None else og
|
||||
|
|
Loading…
Reference in New Issue