fix 'NoneType' object has no attribute 'read' error