简体   繁体   English

任务计划程序中的tempfile.NamedTemporaryFile崩溃

[英]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.

相关问题 如何使用tempfile.NamedTemporaryFile()? - How to use tempfile.NamedTemporaryFile()? 如何使用 tempfile.NamedTemporaryFile() 保存图像? - How to use tempfile.NamedTemporaryFile() to save an image? 如何在python中使用tempfile.NamedTemporaryFile() - how to use tempfile.NamedTemporaryFile() in python Python> 3中的tempfile.TemporaryFile和tempfile.NamedTemporaryFile是否相同 - Are tempfile.TemporaryFile and tempfile.NamedTemporaryFile same in Python > 3 如何打开(两次)使用tempfile.NamedTemporaryFile()创建的文件 - How do I open (twice) file created with tempfile.NamedTemporaryFile() 我可以在 python 中为 tempfile.NamedTemporaryFile 设置 umask 吗? - Can I set the umask for tempfile.NamedTemporaryFile in python? 为什么tempfile.NamedTemporaryFile()会截断我的数据? - Why does tempfile.NamedTemporaryFile() truncate my data? 如何阻止 tempfile.NamedTemporaryFile 在临时文件前缀的末尾添加随机字符? - How to stop tempfile.NamedTemporaryFile from adding random characters to the end of the temp file prefix? Python 2.7 tempfile.NamedTemporaryFile返回类型为“实例”而不是“文件”的对象。 为什么? - Python 2.7 tempfile.NamedTemporaryFile returns object in type 'instance' not 'file'. Why? python 临时文件 | NamedTemporaryFile 不能使用生成的临时文件 - python tempfile | NamedTemporaryFile can't use generated tempfile
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM