requests-html
requests-html copied to clipboard
TypeHint: HTMLSession().get() typehint return is Response instead of HTMLResponse
from requests_html import HTMLSession, HTMLResponse
expected_error_text = "Error"
session: HTMLSession = HTMLSession()
response: HTMLResponse = session.get("https://www.example.com/error")
assert expected_error_text in response.html.find('div.error-page-content')[0].text
In my IntelliJ IDEA the session.get line is highlighted stating:
Expected type 'HTMLResponse', got 'Response' instead
I am assuming the return type for HTMLSession().get() is HTMLResponse because the response actually returned is HTMLResponse.
I'm having the same problem, that the type of return value of get() menthod is requests.response. In the IDE there's warning on response.html that response class have no html attribute. However when I run the code, there is no error, and the functions of response.html is correcrly evaluated.
It's a work around but you can wrap the Response in response_hook
session = HTMLSession()
response = session.get(myof)
response = session.response_hook()
@c3n21 I think it should be:
response = session.response_hook(response)
for the last line