This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: urllib.error.HTTPError.fp is not closed when error is finalized on Windows
Type: behavior Stage:
Components: Library (Lib), Windows Versions: Python 3.11, Python 3.10, Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: orsenthil, paul.moore, puxlit, steve.dower, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2018-10-11 13:49 by puxlit, last changed 2022-04-11 14:59 by admin.

Messages (1)
msg327532 - (view) Author: Xiao Di Guan (puxlit) * Date: 2018-10-11 13:49
Following changes introduced in bpo-15002, HTTPError closes its fp when GCed via tempfile._TemporaryFileCloser's finalizer. However, the current implementation of _TemporaryFileCloser only defines __del__ for non-NT platforms.

Assuming HTTPError.fp is part of the API (though it's currently undocumented), and assuming the desired behaviour is to close fp when HTTPError is finalized, then perhaps _TemporaryFileCloser should always define __del__?

A contrived example follows:

```
from urllib.error import HTTPError
from urllib.request import urlopen

def make_request():
    try:
        urlopen('https://httpbin.org/status/418')
        assert False
    except HTTPError as err:
        assert err.code == 418
        return err.fp

fp = make_request()
assert fp.isclosed()  # Fails on Windows, passes on other platforms
```
History
Date User Action Args
2022-04-11 14:59:07adminsetgithub: 79139
2021-10-22 19:07:56iritkatrielsetnosy: + zach.ware, paul.moore, tim.golden, steve.dower

components: + Windows
versions: + Python 3.9, Python 3.10, Python 3.11, - Python 3.4, Python 3.5, Python 3.6, Python 3.7
2018-10-18 10:14:04puxlitsetnosy: + orsenthil
2018-10-11 13:49:09puxlitcreate