Bytes-only operations like
self._send(c1.raw)
needs to be encoded correctly. Use eitherself._send(bytes(c1.raw, "utf-8"))
orself._send(c1.raw.encode("utf-8"))
However, since your classes like
FinsTCPframe
is actually operating bytes stream instead of unicode literals, I'd suggest to just stick to bytes (appendb
in front of any affected string constants, likeb''
instead of''
ord()
around an item of abytes
instance (for example, ifs
is abytes
instance,s[i]
is the item) should be removed, since retrieving one element from bytes in Python 3.x is already aint
instance. If you are not 100% sure what's inside your ord() call, try this (dirty) workaround:safe_ord = lambda c: ord(c) if isinstance(c, str) else c
And replace corresponding
ord()
withsafe_ord()
chr()
in python 3 returns astr
, but if you needbytes
instead, try this:bytes_chr = lambda x: bytes([x])
(from this stackoverflow question)And replace corresponding
chr()
withbytes_chr()
Division
/
is resulting in a float by default, so if you want to retain the old behavior, double the symbol://
A full list of porting guide can be found on the official python docs site, consult this if you need to do the porting work in the future :)