On 2024-10-08 09:38, José María Mateos wrote:

> On Tue, Oct 8, 2024, at 08:55, Jan Eden via Mutt-users wrote:
> > with open('/var/tmp/htmlfile', 'w', encoding='iso-8859-1') as tmp_file:
> >     ...
> >
> > but this only changed the error message to:
> >
> > 'latin-1' can't encode character '...' in position ...: ordinal not in
> > range(256)
> 
> You can tell open() how to handle errors with the 'errors' keyword. See 
> https://docs.python.org/3/library/functions.html#open:
> 
> ---
> errors is an optional string that specifies how encoding and decoding errors 
> are to be handled—this cannot be used in binary mode. A variety of standard 
> error handlers are available (listed under Error Handlers), though any error 
> handling name that has been registered with codecs.register_error() is also 
> valid. The standard names include:
> 
>     'strict' to raise a ValueError exception if there is an encoding error. 
> The default value of None has the same effect.
> 
>     'ignore' ignores 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.
> ---
> 
> You're not setting it, so it's the same as it being 'strict'. I'd try with 
> 'replace', so you can see characters that were replaced and were potentially 
> problematic.

error='surrogateescape' did the trick – thank you!

- Jan

Attachment: signature.asc
Description: PGP signature

Reply via email to