Skip to content

Commit

Permalink
Merge pull request psf#141 from oldani/bugfix/issue_135
Browse files Browse the repository at this point in the history
Catch typeError on render, add maxretires exception
  • Loading branch information
kennethreitz committed Mar 20, 2018
2 parents 2ef3d41 + ff95ade commit ef67e9f
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion requests_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@
raise RuntimeError('Requests-HTML requires Python 3.6+!')


class MaxRetries(Exception):

def __init__(self, message):
self.message = message


class BaseParser:
"""A basic HTML/Element Parser, for Humans.
Expand Down Expand Up @@ -563,8 +569,13 @@ async def _async_render(*, url: str, script: str = None, scrolldown, sleep: int,
try:

content, result, page = loop.run_until_complete(_async_render(url=self.url, script=script, sleep=sleep, wait=wait, content=self.html, reload=reload, scrolldown=scrolldown, timeout=timeout))
except TimeoutError:
except TypeError:
pass
else:
break

if not content:
raise MaxRetries("Unable to render the page. Try increasing timeout")

html = HTML(url=self.url, html=content.encode(DEFAULT_ENCODING), default_encoding=DEFAULT_ENCODING)
self.__dict__.update(html.__dict__)
Expand Down

0 comments on commit ef67e9f

Please sign in to comment.