MCPcopy Index your code
hub / github.com/microsoft/playwright-python / fetch

Method fetch

playwright/async_api/_generated.py:793–863  ·  view source on GitHub ↗

Route.fetch Performs the request and fetches result without fulfilling it, so that the response could be modified and then fulfilled. **Usage** ```py async def handle(route): response = await route.fetch() json = await response.json(

(
        self,
        *,
        url: typing.Optional[str] = None,
        method: typing.Optional[str] = None,
        headers: typing.Optional[typing.Dict[str, str]] = None,
        post_data: typing.Optional[typing.Union[typing.Any, str, bytes]] = None,
        max_redirects: typing.Optional[int] = None,
        max_retries: typing.Optional[int] = None,
        timeout: typing.Optional[typing.Union[float, datetime.timedelta]] = None,
    )

Source from the content-addressed store, hash-verified

791 )
792
793 async def fetch(
794 self,
795 *,
796 url: typing.Optional[str] = None,
797 method: typing.Optional[str] = None,
798 headers: typing.Optional[typing.Dict[str, str]] = None,
799 post_data: typing.Optional[typing.Union[typing.Any, str, bytes]] = None,
800 max_redirects: typing.Optional[int] = None,
801 max_retries: typing.Optional[int] = None,
802 timeout: typing.Optional[typing.Union[float, datetime.timedelta]] = None,
803 ) -> "APIResponse":
804 """Route.fetch
805
806 Performs the request and fetches result without fulfilling it, so that the response could be modified and then
807 fulfilled.
808
809 **Usage**
810
811 ```py
812 async def handle(route):
813 response = await route.fetch()
814 json = await response.json()
815 json[\"message\"][\"big_red_dog\"] = []
816 await route.fulfill(response=response, json=json)
817
818 await page.route(\"https://dog.ceo/api/breeds/list/all\", handle)
819 ```
820
821 **Details**
822
823 Note that `headers` option will apply to the fetched request as well as any redirects initiated by it. If you want
824 to only apply `headers` to the original request, but not to redirects, look into `route.continue_()`
825 instead.
826
827 Parameters
828 ----------
829 url : Union[str, None]
830 If set changes the request URL. New URL must have same protocol as original one.
831 method : Union[str, None]
832 If set changes the request method (e.g. GET or POST).
833 headers : Union[Dict[str, str], None]
834 If set changes the request HTTP headers. Header values will be converted to a string.
835 post_data : Union[Any, bytes, str, None]
836 Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string
837 and `content-type` header will be set to `application/json` if not explicitly set. Otherwise the `content-type`
838 header will be set to `application/octet-stream` if not explicitly set.
839 max_redirects : Union[int, None]
840 Maximum number of request redirects that will be followed automatically. An error will be thrown if the number is
841 exceeded. Defaults to `20`. Pass `0` to not follow redirects.
842 max_retries : Union[int, None]
843 Maximum number of times network errors should be retried. Currently only `ECONNRESET` error is retried. Does not
844 retry based on HTTP response codes. An error will be thrown if the limit is exceeded. Defaults to `0` - no retries.
845 timeout : Union[float, None]
846 Request timeout in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout.
847
848 Returns
849 -------
850 APIResponse

Callers 1

fetchMethod · 0.45

Calls 3

to_millisecondsFunction · 0.90
from_implMethod · 0.80
to_implMethod · 0.80

Tested by

no test coverage detected