There is a problem on Windows with NamedTemporaryFile:
NamedTemporaryFile actually creates the file for you, there's no need for you to open it for write.
In fact, the Python docs state:
Whether the name can be used to open the file a second time, while the named temporary file is still open, varies across platforms (it can be so used on Unix; it cannot on Windows NT or later).
t_cookie_file = tempfile.NamedTemporaryFile(suffix='.sqlite', mode="wb", delete=False) t_cookie_file.write(open(cookie_file, 'rb').read()) tmp_cookie_file = t_cookie_file.name t_cookie_file.close()
tmp_cookie_file = tempfile.NamedTemporaryFile(suffix='.sqlite').name open(tmp_cookie_file, 'wb').write(open(cookie_file, 'rb').read())