The problem was that Python 3 wants a bytes object and not a string.
So we have to encode the string first to make it useable. Python 2 handles
bytes objects as normal strings so the fix should be backwards compatible.
Furthermore this commit adds a massive performance improvement by collecting
all bytes in a list and calling "join" at the end. This is significantly
faster than simply appending each byte to the bytes object one at one.
https://forum.freecadweb.org/viewtopic.php?f=3&t=35032