use encodebytes for Python 3 to avoid DeprecationWarning