all Python 3codecsfunction
codecs.lookup_error()
error handlers
Returns an error handler function by name: a built-in one ('strict', 'replace', 'surrogateescape'…) or one registered with register_error.
Syntax
handler = codecs.lookup_error(name)
Useful inside your own handler to delegate to standard behaviour: codecs.lookup_error('replace')(err). For the five classic names the result is the very same object as codecs.replace_errors and its siblings. An unknown name raises LookupError, and a typo like errors='repalce' in encode also surfaces only at the first encoding error, not earlier.
Examples
import codecs
print(codecs.lookup_error('replace') is codecs.replace_errors) # → True
print('ok'.encode('ascii', 'repalce')) # → b'ok' — опечатка не замечена: ошибок не было
try:
'é'.encode('ascii', 'repalce')
except LookupError as e:
print(e) # → unknown error handler name 'repalce'
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy