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', thebodywill be sent tohttpx.request()through thejsonparameter -
If
payload_type='raw', thebodywill be sent tohttpx.request()through thecontentparameter -
If
payload_type='form'thebodywill be sent tohttpx.request()through thedataparameter
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
RequestParametersand custom headers are provided -
Raises a ValueError if one of the header flags are set to true in
RequestParametersand no custom headers are provided -
Raises a ValueError if
RequestParameters.extra_headersis set to true and any of the provided headers don't start with the requiredsd-prefix.
Method
- Raises a ValueError if
RequestParameters.renderis set to true andmethod != "GET"
Body
- Emits a UserWarning if a
bodyis provided andmethod=GETormethod=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 |