redis/redis-py · error · ValueError
must not contain spaces, newlines, non-printable…
Error message
{field_name} must not contain spaces, newlines, non-printable characters, or braces What it means
_validate_no_invalid_chars (redis/driver_info.py:21) rejects any character outside printable ASCII 0x21-0x7E and also forbids the brace set ()[]{}. These strings become the LIB-NAME / LIB-VER sent via CLIENT SETINFO and appear in CLIENT LIST / CLIENT INFO output, where spaces, newlines and braces would corrupt Redis' single-line format or enable injection. The validator runs on the base lib name, the lib version, each upstream driver name, and each upstream driver version.
Solutions
- Sanitize the value to printable ASCII without spaces or braces before constructing DriverInfo or calling add_upstream_driver.
- Strip whitespace/newlines and replace unicode dashes/quotes with their ASCII equivalents.
- Keep driver/version strings to the form /^[!-~]+$/ minus ()[]{} — typically alnum, dots, hyphens, underscores.
Example fix
// before info = redis.driver_info.DriverInfo(name='My Redis Client 2.0') // after info = redis.driver_info.DriverInfo(name='MyRedisClient-2.0')
Defensive patterns
Strategy: validation
Validate before calling
import re
def safe_driver_value(v: str) -> str:
return re.sub(r'\s+', '', v).encode('ascii', 'ignore').decode('ascii')
def is_valid_value(v: str) -> bool:
return all(0x21 <= ord(c) <= 0x7E and c not in '()[]{}' for c in v) Type guard
def is_clean_ascii(v) -> bool:
return isinstance(v, str) and all(0x21 <= ord(c) <= 0x7E and c not in '()[]{}' for c in v) Prevention
- Keep driver/version strings to alnum, dots, hyphens, underscores only.
- Normalize unicode dashes/quotes/smart punctuation to ASCII before constructing DriverInfo.
- Strip whitespace and newlines from auto-derived version strings.
When it happens
Trigger: Calling DriverInfo(name=..., lib_version=...) or driver_info.add_upstream_driver(name, version) with a value containing a space, tab, newline, non-ASCII char (e.g. a unicode dash), or any of ()[]{}. Passing a version with a trailing newline or a driver name copied from a rich-text doc with smart quotes will trigger it.
Common situations: Auto-derived versions that include git describe suffixes with special chars; pasting driver names from marketing copy; unicode lookalikes (en-dash instead of hyphen); building lib_name from user input that contains spaces.
Related errors
- driver_info must be a DriverInfo instance or None
- Driver name must not be None
- Driver version must not be None
- Upstream driver name must use a Python package-style name…
- ACL LOG count must be an integer
AI-assisted analysis of redis/redis-py@6a6b581b48 (2026-08-10).
Data as JSON: /api/errors/5b69f275f555f9f4.
Report an issue: GitHub.
Appendix: source
Thrown at redis/driver_info.py:21
from dataclasses import dataclass, field
from typing import List, Optional
from redis.utils import SENTINEL
_BRACES = {"(", ")", "[", "]", "{", "}"}
def _validate_no_invalid_chars(value: str, field_name: str) -> None:
"""Ensure value contains only printable ASCII without spaces or braces.
This mirrors the constraints enforced by other Redis clients for values that
will appear in CLIENT LIST / CLIENT INFO output.
"""
for ch in value:
# printable ASCII without space: '!' (0x21) to '~' (0x7E)
if ord(ch) < 0x21 or ord(ch) > 0x7E or ch in _BRACES:
raise ValueError(
f"{field_name} must not contain spaces, newlines, non-printable characters, or braces"
)
def _validate_driver_name(name: str) -> None:
"""Validate an upstream driver name.
The name should look like a typical Python distribution or package name,
following a simplified form of PEP 503 normalisation rules:
* start with a lowercase ASCII letter
* contain only lowercase letters, digits, hyphens and underscores
Examples of valid names: ``"django-redis"``, ``"celery"``, ``"rq"``.
"""
import re
View on GitHub (pinned to 6a6b581b48)