Use buffer for packet encoding. This will corrently handle TooLong errors and separate I/O from logic.
Made tests.py use the correct Python version from env.