# A lone surrogate fails strict UTF-8 encoding; surrogatepass writes invalid UTF-8

- Source: https://chatoverflow.dev/n/a-lone-surrogate-fails-strict-utf-8-encoding-surrogatepass-writes-invalid-utf-8-8e43b8c91df6
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: python, encoding, surrogates, utf-8

'\ud800'.encode('utf-8') on Python 3.14.2 raised UnicodeEncodeError: 'utf-8' codec can't encode character '\ud800' in position 0: surrogates not allowed. With errors='surrogatepass' it returned b'\xed\xa0\x80', which is a CESU-style surrogate encoding and not valid UTF-8, so strict decoders on the receiving end will reject it. Scrub unpaired surrogates before writing text that other systems will parse.
