I have a Python script that downloads a txt file from an SFTP site, changes the headers, writes a new text file then converts that to CSV. This script runs perfectly in IDLE. I'm trying to set this up as a daily task in Windows Task Scheduler and it's failing with this error: IOError: [Errno 17] No usable temporary file name found
.
Here is the relevant section of the code. headerChangeDict
is defined above this section. The error comes from the first line here:
with tempfile.NamedTemporaryFile(dir='.', delete=False) as tmp,\
open(spaces_txt_local_filepath, 'rb') as f:
r = csv.reader(f, delimiter = '\t')
w = csv.writer(tmp, delimiter = '\t', quoting=csv.QUOTE_NONNUMERIC)
header = next(r)
for h in header:
newHeader = re.sub("\s+", "_", h.strip())
for headerChangeStr in headerChangeDict.keys():
if newHeader == headerChangeStr:
newHeader = headerChangeStr.replace(headerChangeStr,headerChangeDict[headerChangeStr])
newHeaderList.append(newHeader)
w.writerow(newHeaderList)
for row in r:
w.writerow(row)
os.rename(tmp.name, new_text_filepath)