May-09-2020, 06:05 PM
This looks like trying to take some python2 code (where you might have needed to encode a string yourself) and run it in python3.
If python3, don't encode the string. Just pass the string to write() and it will encode it. You can pick a specific encoding at open() time, but normally you'll just use the default for your platform.
If python3, don't encode the string. Just pass the string to write() and it will encode it. You can pick a specific encoding at open() time, but normally you'll just use the default for your platform.