Network-shaped failures without fragile parsing
Intermediate
Defensive APIs: validation, sanitization & exceptions
Created by Pavel
· 29.04.2026 at 19:10 UTC
HTTP layers deliver bytes on the wire; JSON parsers want text; base64 wraps binary inside ASCII. Mixing these causes classic bugs: calling .json() on undecoded bytes, double-decoding UTF-8, or assuming Content-Type matches the body.
Robust clients: read bytes → decode with declared charset → json.loads → validate with Pydantic or manual checks. When scraping or using partner APIs, separate transport, parsing, and validation so failures pinpoint the broken layer.
requests response content vs text: [1].
Sources
University approvals: 0
Tasks
Card Info
- Topic: Defensive APIs: validation, sanitization & exceptions
- Difficulty: Intermediate
- Completed: 0 users
Creator
Pavel