A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://playwright.dev/python/docs/api/class-apiresponse below:

APIResponse | Playwright Python

APIResponse

APIResponse class represents responses returned by api_request_context.get() and similar methods.

from playwright.sync_api import sync_playwright

with sync_playwright() as p:
context = playwright.request.new_context()
response = context.get("https://example.com/user/repos")
assert response.ok
assert response.status == 200
assert response.headers["content-type"] == "application/json; charset=utf-8"
assert response.json()["name"] == "foobar"
assert response.body() == '{"status": "ok"}'
import asyncio
from playwright.async_api import async_playwright, Playwright

async def run(playwright: Playwright):
context = await playwright.request.new_context()
response = await context.get("https://example.com/user/repos")
assert response.ok
assert response.status == 200
assert response.headers["content-type"] == "application/json; charset=utf-8"
json_data = await response.json()
assert json_data["name"] == "foobar"
assert await response.body() == '{"status": "ok"}'


async def main():
async with async_playwright() as playwright:
await run(playwright)

asyncio.run(main())
Methods bodyAdded in: v1.16 apiResponse.body

Returns the buffer with response body.

Usage

Returns

disposeAdded in: v1.16 apiResponse.dispose

Disposes the body of this response. If not called then the body will stay in memory until the context closes.

Usage

Returns

jsonAdded in: v1.16 apiResponse.json

Returns the JSON representation of response body.

This method will throw if the response body is not parsable via JSON.parse.

Usage

Returns

textAdded in: v1.16 apiResponse.text

Returns the text representation of response body.

Usage

Returns

Properties Added in: v1.16 apiResponse.headers

An object with all the response HTTP headers associated with this response.

Usage

Returns

Added in: v1.16 apiResponse.headers_array

An array with all the response HTTP headers associated with this response. Header names are not lower-cased. Headers with multiple entries, such as Set-Cookie, appear in the array multiple times.

Usage

api_response.headers_array

Returns

okAdded in: v1.16 apiResponse.ok

Contains a boolean stating whether the response was successful (status in the range 200-299) or not.

Usage

Returns

statusAdded in: v1.16 apiResponse.status

Contains the status code of the response (e.g., 200 for a success).

Usage

Returns

status_textAdded in: v1.16 apiResponse.status_text

Contains the status text of the response (e.g. usually an "OK" for a success).

Usage

Returns

urlAdded in: v1.16 apiResponse.url

Contains the URL of the response.

Usage

Returns


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4