Skip to content

Commit bc845ee

Browse files
committed
Catch urllib.error.URLError to prevent crashes
Fixes kurtmckee#239
1 parent 129b309 commit bc845ee

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
coming in the next release:
22

3+
6.0.7 - 21 June 2021
4+
* Catch ``urllib.error.URLError`` to prevent crashes. (#239)
5+
36
6.0.6 - 15 June 2021
47
* Prevent an AttributeError that occurs when a server returns HTTP 3xx
58
but doesn't include a Location header as well. (#267)

feedparser/api.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
# POSSIBILITY OF SUCH DAMAGE.
2828

2929
import io
30+
import urllib.error
3031
import urllib.parse
3132
import xml.sax
3233

@@ -211,7 +212,14 @@ def parse(url_file_stream_or_string, etag=None, modified=None, agent=None, refer
211212
headers={},
212213
)
213214

214-
data = _open_resource(url_file_stream_or_string, etag, modified, agent, referrer, handlers, request_headers, result)
215+
try:
216+
data = _open_resource(url_file_stream_or_string, etag, modified, agent, referrer, handlers, request_headers, result)
217+
except urllib.error.URLError as error:
218+
result.update({
219+
'bozo': True,
220+
'bozo_exception': error,
221+
})
222+
return result
215223

216224
if not data:
217225
return result

0 commit comments

Comments
 (0)