Skip to content
Advertisement

python tempfile | NamedTemporaryFile can’t use generated tempfile

I would like to load the temp file to make changes or just be able to upload it somewhere, When I try to do so – It throws an error as shown below

I have set the permission to w+ – which should ideally allow me to read and write, Not sure what am I missing here – Any help would be appreciated – thanks

JavaScript

Advertisement

Answer

You’re on Windows, evidently.

On Windows, you can’t open another handle to a O_TEMPORARY file while it’s still open (see e.g. https://github.com/bravoserver/bravo/issues/111, https://docs.python.org/3/library/tempfile.html#tempfile.NamedTemporaryFile, https://bugs.python.org/issue14243).

You’ll need to use delete=False and clean up manually, e.g.

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement