[英]tempfile.NamedTemporaryFile crashing in Task Scheduler
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. 我有一个Python脚本,该脚本从SFTP站点下载txt文件,更改标题,写入新的文本文件,然后将其转换为CSV。 This script runs perfectly in IDLE.
该脚本可以在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
. 我试图将其设置为Windows Task Scheduler中的日常任务,并且由于以下错误而失败:
IOError: [Errno 17] No usable temporary file name found
。
Here is the relevant section of the code. 这是代码的相关部分。
headerChangeDict
is defined above this section. headerChangeDict
在此部分的上headerChangeDict
。 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)
Ah, I got it. 啊,我明白了。 I needed to change dir='.'
我需要更改dir ='。 to the specified temp path where this script is writing the text and csv files.
到指定的临时路径,此脚本在其中写入文本和csv文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.