requests-html icon indicating copy to clipboard operation
requests-html copied to clipboard

TypeHint: HTMLSession().get() typehint return is Response instead of HTMLResponse

Open balexander85 opened this issue 3 years ago • 3 comments

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.

balexander85 avatar Jan 13 '21 16:01 balexander85

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.

cby120 avatar Feb 19 '21 07:02 cby120

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 avatar Aug 03 '21 10:08 c3n21

@c3n21 I think it should be:

response = session.response_hook(response)

for the last line

chouwwa avatar Mar 23 '23 22:03 chouwwa