dev_path="/dev/usb/lp0" def print_text(stream, text): stream.write(text.encode('utf-8')) def cut_paper(stream): stream.write(b'\x1DVA\xc8') def print_image(image): buffer = io.BytesIO() image.save(buffer, format='PBM') pbm_base64 = base64.b64encode(buffer.getvalue()).decode('utf-8') stream = open('/dev/usb/lp0', 'wb') print_text(stream, "test\n") cut_paper(stream) stream.close()