Source code for human_requests.abstraction.response

from dataclasses import dataclass
from typing import AsyncContextManager, Callable, Literal, Optional

from playwright.async_api import Page

from .cookies import Cookie
from .http import URL
from .request import Request


@dataclass(frozen=True)
[docs] class Response: """Represents the response of a request."""
[docs] request: Request
"""The request that was made."""
[docs] url: URL
"""The URL of the response. Due to redirects, it can differ from `request.url`."""
[docs] headers: dict
"""The headers of the response."""
[docs] cookies: list[Cookie]
"""The cookies of the response."""
[docs] body: str
"""The body of the response."""
[docs] status_code: int
"""The status code of the response."""
[docs] duration: float
"""The duration of the request in seconds.""" _render_callable: Optional[Callable[..., AsyncContextManager[Page]]] = None
[docs] def render( self, wait_until: Literal["commit", "load", "domcontentloaded", "networkidle"] = "commit", retry: int = 2, ) -> AsyncContextManager[Page]: """Renders the response content in the current browser. It will look like we requested it through the browser from the beginning. Recommended to use in cases when the server returns a JS challenge instead of a response.""" if self._render_callable: return self._render_callable(self, wait_until=wait_until, retry=retry) raise ValueError("Not set render callable for Response")