Open ahaoboy opened 11 months ago
You haven't provided enough information here to debug this: how does the browser fail?
I suspect this is an "open for sharing" problem on Windows. You might be able to use the opener
argument to open()
to create a file that has the sharing permissions you're after. But you'll have to know what sharing access the browser is requesting. And then it probably wouldn't work with NamedTemporaryFile
(I haven't delved into the details to see if you can specify an opener with NamedTemporaryFile
).
You haven't provided enough information here to debug this: how does the browser fail?
I suspect this is an "open for sharing" problem on Windows. You might be able to use the
opener
argument toopen()
to create a file that has the sharing permissions you're after. But you'll have to know what sharing access the browser is requesting. And then it probably wouldn't work withNamedTemporaryFile
(I haven't delved into the details to see if you can specify an opener withNamedTemporaryFile
).
I updated the bug report.
Bug report
Bug description:
Create a temporary file, write html content, invoke the flush function, then wait for user input. At this point, the file exists and can be opened via VSCode or cat, but cannot be accessed through a web browser.
After test with two win11 pc and edge/chrome/firefox, I find some interesting things
delete_on_close=True
and don't close after flush, all browsers cannot find the file.delete_on_close=False
, whether or not you close the file, all browsers can open the fileYou can also open it by copying and pasting the fileurl or by right-clicking with the mouse. The result is the same.
chrome/edge firefox is waiting forever and do nothing
CPython versions tested on:
3.12
Operating systems tested on:
Windows