python 'str' object has no attribute 'close'