scrapy/scrapy · error · TypeError
Request priority not an integer: {priority!r}
Error message
Request priority not an integer: {priority!r} What it means
Request.__init__ raises TypeError when the priority argument is not an int (bool counts as int and passes; floats and strings do not). Priority is used directly by built-in schedulers for ordering and must be an exact integer to keep comparisons and deque ordering deterministic; a bool like True would silently work as 1, but 1.0 or '1' fail this guard before any scheduling happens.
Source
Thrown at scrapy/http/request/__init__.py:149
| Iterable[tuple[str | bytes, Any]]
| None = None,
body: bytes | str | None = None,
cookies: CookiesT | None = None,
meta: dict[str, Any] | None = None,
encoding: str = "utf-8",
priority: int = 0,
dont_filter: bool = False,
errback: Callable[[Failure], Any] | None = None,
flags: list[str] | None = None,
cb_kwargs: dict[str, Any] | None = None,
) -> None:
self._encoding: str = encoding # this one has to be set first
self.method: str = str(method).upper()
self._meta: dict[str, Any] | None = dict(meta) if meta else None
self._set_url(url)
self._set_body(body)
if not isinstance(priority, int):
raise TypeError(f"Request priority not an integer: {priority!r}")
#: Default: ``0``
#:
#: Value that the :ref:`scheduler <topics-scheduler>` may use for
#: request prioritization.
#:
#: Built-in schedulers prioritize requests with a higher priority
#: value.
#:
#: Negative values are allowed.
self.priority: int = priority
if not (callable(callback) or callback is None):
raise TypeError(
f"callback must be a callable, got {type(callback).__name__}"
)
if not (callable(errback) or errback is None):
raise TypeError(f"errback must be a callable, got {type(errback).__name__}")View on GitHub (pinned to 06af687662)
Solutions
- Coerce to int at the call site: priority=int(priority) after validating the value
- If you need fractional ordering, scale to integers (e.g. priority * 100 as int) since built-in schedulers only accept int
- Cast external config once at load: priority = int(settings['PRIORITY'])
- Add a unit assertion in helpers that build requests from untrusted data: isinstance(priority, int)
Example fix
# before
Request(url, priority=0.5) # TypeError
Request(url, priority='10') # TypeError
# after
Request(url, priority=1)
Request(url, priority=int('10'))
# scaled fractional ordering:
Request(url, priority=int(0.5 * 100)) Defensive patterns
Strategy: validation
Validate before calling
if not isinstance(priority, int):
priority = int(priority) # or raise with context
Request(url, priority=priority) Type guard
def is_valid_priority(p) -> bool:
return isinstance(p, int) and not isinstance(p, bool) or isinstance(p, bool) Try / catch
null
Prevention
- Convert numeric config values to int once at load time
- Use integer scaling for fractional priorities
- Assert types in request-builder helpers fed by external data
When it happens
Trigger: Request(url, priority=1.5) or priority=float(some_setting); priority computed as '10' from a string config; passing a numpy integer type (not a Python int, so isinstance fails); templated code where priority comes from an untyped source like CSV/JSON.
Common situations: Priority read from settings/env as string and not converted; float arithmetic ('base + 0.5 * depth') feeding priority; interop with libraries returning non-int numerics (numpy.int64 is actually fine on CPython but Decimal/float are not).
Related errors
- callback must be a callable, got {type(callback).__name__}
- errback must be a callable, got {type(errback).__name__}
- Request url must be str, got {type(url).__name__}
- Unsupported value type: {type(x)}
- Invalid value {value} for component {name}, please provide a
AI-assisted analysis of scrapy/scrapy@06af687662 (2026-08-15).
Data as JSON: /api/errors/0e41b58d7c0044cb.
Report an issue: GitHub.