1. Have catch-all exception handling. Exception may not be your fault, exception-caused "crashing" whatever that means is entirely your fault.
2. Use os.fsdecode. https://docs.python.org/3/library/os.html#os.fsdecode
3. Don't process random untrusted filenames. Sanitize if it's some sort of HTTP upload, for instance.
Then you can use the 'bytes' variant of calls. If you process arbitrary data, there's lots of things you need to think about. This is just one of them. And if you'd crash otherwise, you should have exception handling in place.
I understand it's a problem and it's not trivial to support this, but it's not difficult either.
Possible, sure, but highly unlikely. Unless you consider black-hat hackers, it’s pretty rare for modern software to be fed decades-old files.
what if you are trying to process "foreign"(as in, not created by you) filenames, trying to validate/conform with python? I mean its a great DoS vector, which is difficult to protect against with python.
it'll crash. Which the point the article is trying to make.
> unless you’ve kept files around for decades, you don’t.
Thats both untrue and not very helpful. Its perfectly possible to bump into files like this.