Fix API.request_url() with Py3.13 (#208)
Since Python 3.13, the IOBase finalizer now logs any errors raised by the close() method https://docs.python.org/3/whatsnew/3.13.html#io
According to
https://docs.python.org/3.13/library/io.html#io.IOBase.close
if the file (descriptor) is accessed after being close,
ValueError
is raised.
The fd
is copied with copy.copy()
.
Both gets automatically closed once the function ends,
the second can’t close a second time the same fd,
that’s why we get this error.
Reorganise complex function: don’t use with
since the function is designed to allow returning the fd.
Drop copy.copy()
used previously to return the fd, causing the issue.
Cleanly separate three return types and function’s returns.
Close #208 (closed).
Merge request reports
Activity
changed milestone to %1.3.0
assigned to @moul
requested review from @vtexier
changed milestone to %1.2.1
- Resolved by Vincent Texier
The copy is used here because
response.read()
remove all data from theresponse
fd
data buffer !So
response
will be empty without the copy...May be you can close and destroy the copy just after the
response.read()
like this :response_copy = copy.copy(response) content = response_copy.read().decode("utf-8") del(response_copy) result = response # response data buffer is preserved, and can be returned
Edited by Vincent Texier
added 1 commit
- 013486f5 - Fix API.request_url() with Py3.13 (#208 (closed))
added 1 commit
- e10b2425 - Fix API.request_url() with Py3.13 (#208 (closed))