Skip to content

Commit

Permalink
Merge pull request psf#162 from SN9NV/patch-2
Browse files Browse the repository at this point in the history
Replace errors when decoding raw_html
  • Loading branch information
kennethreitz committed Sep 18, 2018
2 parents a693658 + 05ff6e8 commit f760df2
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions requests_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def html(self) -> _BaseHTML:
(`learn more <http://www.diveintopython3.net/strings.html>`_).
"""
if self._html:
return self.raw_html.decode(self.encoding)
return self.raw_html.decode(self.encoding, errors='replace')
else:
return etree.tostring(self.element, encoding='unicode').strip()

Expand All @@ -128,7 +128,7 @@ def encoding(self) -> _Encoding:
self._encoding = html_to_unicode(self.default_encoding, self._html)[0]
# Fall back to requests' detected encoding if decode fails.
try:
self.raw_html.decode(self.encoding)
self.raw_html.decode(self.encoding, errors='replace')
except UnicodeDecodeError:
self._encoding = self.default_encoding

Expand Down

0 comments on commit f760df2

Please sign in to comment.