Ok, i found the problems. First problem the complete code is not pep8 and mixes tabs and spaces. The second problem some variables doesnt use correct namesspace and also mssing binary opening mode exist.