Skip to content

Request

request

Serialization layer and HTTP transport preparation.

Bridges the gap between the strictly validated Pydantic models and the underlying HTTP client. It wraps the API parameters, handles URL encoding, manages payload typing, and injects authentication token before network execution.

PreparedScrapeDoRequest

Bases: BaseModel

Represents a fully validated, ready-to-execute API call.

Payload Type
  • If payload_type='json', the body will be sent to httpx.request() through the json parameter

  • If payload_type='raw', the body will be sent to httpx.request() through the content parameter

  • If payload_type='form' the body will be sent to httpx.request() through the data parameter

Attributes:

Name Type Description
api_params RequestParameters

Validated parameters to pass to the API

method HttpMethod

HTTP method to forward to the target website

headers Optional[Dict[str, str]]

Custom HTTP headers to forward

body Optional[Union[Dict[str, Any], str, bytes]]

Payload to send to the target website (JSON dict, string, or bytes)

payload_type PayloadType

Dictates how httpx should encode the body. Defaults to 'json'.

cross_validate_http_components()

Cross-references standard HTTP request components (Method, Headers, Body) against the Scrape.do specific parameters to ensure the configuration will be respected by the proxy network.

Headers
  • Raises a ValueError if none of the header flags is set to true in RequestParameters and custom headers are provided

  • Raises a ValueError if one of the header flags are set to true in RequestParameters and no custom headers are provided

  • Raises a ValueError if RequestParameters.extra_headers is set to true and any of the provided headers don't start with the required sd- prefix.

Method
  • Raises a ValueError if RequestParameters.render is set to true and method != "GET"
Body
  • Emits a UserWarning if a body is provided and method=GET or method=HEAD

Returns:

Type Description
Self

The validated instance from which the method was called

Raises:

Type Description
ValueError

If any of the validation steps fails

to_httpx_kwargs(token=None)

Packages the validated object into a dictionary ready for httpx unpacking.

Token

The optional token parameter is the user's Scrape.do API key and is only added here only for convenience. It can also be manuall inserted into the resulting httpx_kwargs dictionary as the value to the token key if it isn't provided

Parameters:

Name Type Description Default
token Optional[str]

The Scrape.do API key to include in the dictionary

None

Returns:

Type Description
Dict[str, Any]

Keyword arguments strictly formatted for httpx.request().