Represent binary downloads
A downloader or test needs a generic container for a binary HTTP payload.
Scrapy · Class
scrapy.http.Response represents an HTTP response downloaded by Scrapy and passed to a spider. It stores the URL, status, headers, raw byte body, and optional flags.
Response is Scrapy's base container for a downloaded HTTP result. Construct it with a URL and optional status, headers, byte body, and flags; use specialized subclasses such as TextResponse when the payload needs decoded text or selector support.
scrapy.http.Response(**args: Any, **kwargs: Any)| Name | Type | Description |
|---|---|---|
url | str | URL associated with the response. |
status | int | HTTP status code; defaults to 200. |
headers | dict | Response headers; values may be strings or lists. |
body | bytes | Raw response payload. |
flags | list | Initial values for Response.flags. |
A scrapy.http.Response object representing an HTTP response.
from scrapy.http import Response
response = Response(
url="https://example.com/data.bin",
status=200,
headers={"Content-Type": ["application/octet-stream"]},
body=b"binary data",
flags=["cached"],
)
print(response.url)
print(response.status)
print(response.body)Creates a base Response for binary content and reads its URL, status, and raw byte body.
A downloader or test needs a generic container for a binary HTTP payload.
A unit test needs a controlled HTTP result without making a network request.
A spider needs status, headers, or URL metadata while processing a result.
Response represents an HTTP result downloaded by Scrapy and passed to a spider. Its core construction accepts a URL, with status defaulting to 200, plus optional headers, body, and flags.
Follow-up: How should textual content be handled? Use an encoding-aware subclass such as TextResponse, which provides decoded text access through response.text.
The body parameter is bytes, and the base Response is meant for binary payloads. The response URL, status, headers, and flags describe the downloaded result.
Follow-up: Why not pass decoded text as the body? Because the documented body type is bytes; decoding belongs to an encoding-aware Response subclass.
Response.headers is a dictionary whose values can be strings for single-valued headers or lists for multi-valued headers. Response.flags receives the initial values for the flags attribute.
Follow-up: What subclass is appropriate for HTML or other encoded text? TextResponse adds encoding capabilities to the base class.
scrapy.http.Requestscrapy.http.TextResponseResponse.requestResponse.urlResponse.statusResponse.headersResponse.bodyResponse.flags