using tempfile.NamedTemporaryFile() as suggested. removed uneccessary import.