'What is the function of the 'errors' parameter to subprocess.Popen()?

The python subprocess docs only mention the errors parameter in passing:

If encoding or errors are specified, or universal_newlines is true, file objects for stdin, stdout and stderr are opened in text mode using the specified encoding and errors or the io.TextIOWrapper default.

I understand the usage of text and universal_newlines, which are synonyms. I also understand the usage of encoding.

What is the function of the errors parameter? It appears to have been added in Python 3.6. Is errors just a synonym of encoding? If it is just a synonym, are there any published reasoning for this addition?



Solution 1:[1]

The errors parameter is described in the linked documentation for io.TextIOWrapper:

errors is an optional string that specifies how encoding and decoding errors are to be handled. Pass 'strict' to raise a ValueError exception if there is an encoding error (the default of None has the same effect), or pass 'ignore' to ignore errors. (Note that ignoring encoding errors can lead to data loss.) 'replace' causes a replacement marker (such as '?') to be inserted where there is malformed data. 'backslashreplace' causes malformed data to be replaced by a backslashed escape sequence. When writing, 'xmlcharrefreplace' (replace with the appropriate XML character reference) or 'namereplace' (replace with \N{...} escape sequences) can be used. Any other error handling name that has been registered with codecs.register_error() is also valid.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 larsks