Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Scrapy · Class

Response

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.

How it works

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.

Syntax

scrapy.http.Response(**args: Any, **kwargs: Any)

Parameters

NameTypeDescription
urlstrURL associated with the response.
statusintHTTP status code; defaults to 200.
headersdictResponse headers; values may be strings or lists.
bodybytesRaw response payload.
flagslistInitial values for Response.flags.

Returns

A scrapy.http.Response object representing an HTTP response.

Key points

  • Response is the base object for representing HTTP responses inside Scrapy.
  • The downloader normally creates or supplies the response that a spider processes.
  • url identifies the resource associated with the response.
  • status records the HTTP result code and defaults to 200 when omitted.
  • body stores the raw response payload as bytes.
  • flags can be initialized with labels that annotate the response.

Common mistakes

  • The base class is intended for binary data; do not treat its body as decoded text. Use an encoding-aware subclass for text access.
  • Header values may represent one value or multiple values, so preserve the documented string-or-list shape.

Example: Construct a binary 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.

When to use it

Represent binary downloads

A downloader or test needs a generic container for a binary HTTP payload.

Build test responses

A unit test needs a controlled HTTP result without making a network request.

Inspect response metadata

A spider needs status, headers, or URL metadata while processing a result.

Interview questions

QWhat is scrapy.http.Response used for?

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.

QWhat are the important constructor parameters?

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.

QHow do headers and flags behave?

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.Request
  • scrapy.http.TextResponse
  • Response.request
  • Response.url
  • Response.status
  • Response.headers
  • Response.body
  • Response.flags

Source: Requests and Responses. Checked 2026-10-15.