Skip to content
Snippets Groups Projects
Commit 8d7c2d60 authored by Moul's avatar Moul
Browse files

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.

Not sure if there is a use case with the fd copy
Fix: remove fd copy
parent 58540690
No related branches found
No related tags found
No related merge requests found
Pipeline #38426 passed
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
import copy
import json import json
import logging import logging
from http.client import HTTPResponse from http.client import HTTPResponse
...@@ -269,7 +268,6 @@ class API: ...@@ -269,7 +268,6 @@ class API:
raise ValueError(f"status code != 200 => {response.status} ({content})") raise ValueError(f"status code != 200 => {response.status} ({content})")
# get response content # get response content
return_response = copy.copy(response)
content = response.read().decode("utf-8") content = response.read().decode("utf-8")
# if schema supplied... # if schema supplied...
...@@ -278,7 +276,7 @@ class API: ...@@ -278,7 +276,7 @@ class API:
parse_response(content, schema) parse_response(content, schema)
# return the chosen type # return the chosen type
result = return_response # type: Any result = response # type: Any
if rtype == RESPONSE_TEXT: if rtype == RESPONSE_TEXT:
result = content result = content
elif rtype == RESPONSE_JSON: elif rtype == RESPONSE_JSON:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment