Fix AttributeError: 'NoneType' object has no attribute 'read' #3570