mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-20 19:17:11 +00:00
Make python code compatible with urllib3 v2.6.0+ (#22520)
openapi-generator still uses methods that have been removed from urllib3 v2.6.0. The solution is as described in urllib3's changelog: > Removed the HTTPResponse.getheaders() method in favor of > HTTPResponse.headers. Removed the HTTPResponse.getheader(name, > default) method in favor of HTTPResponse.headers.get(name, default). > (#3622) See https://urllib3.readthedocs.io/en/latest/changelog.html Close #22514
This commit is contained in:
@@ -313,7 +313,7 @@ class ApiClient:
|
||||
return_data = self.__deserialize_file(response_data)
|
||||
elif response_type is not None:
|
||||
match = None
|
||||
content_type = response_data.getheader('content-type')
|
||||
content_type = response_data.headers.get('content-type')
|
||||
if content_type is not None:
|
||||
match = re.search(r"charset=([a-zA-Z\-\d]+)[\s;]?", content_type)
|
||||
encoding = match.group(1) if match else "utf-8"
|
||||
@@ -330,7 +330,7 @@ class ApiClient:
|
||||
return ApiResponse(
|
||||
status_code = response_data.status,
|
||||
data = return_data,
|
||||
headers = response_data.getheaders(),
|
||||
headers = response_data.headers,
|
||||
raw_data = response_data.data
|
||||
)
|
||||
|
||||
@@ -702,7 +702,7 @@ class ApiClient:
|
||||
os.close(fd)
|
||||
os.remove(path)
|
||||
|
||||
content_disposition = response.getheader("Content-Disposition")
|
||||
content_disposition = response.headers.get("Content-Disposition")
|
||||
if content_disposition:
|
||||
m = re.search(
|
||||
r'filename=[\'"]?([^\'"\s]+)[\'"]?',
|
||||
|
||||
@@ -129,7 +129,7 @@ class ApiException(OpenApiException):
|
||||
self.body = http_resp.data.decode('utf-8')
|
||||
except Exception:
|
||||
pass
|
||||
self.headers = http_resp.getheaders()
|
||||
self.headers = http_resp.headers
|
||||
|
||||
@classmethod
|
||||
def from_response(
|
||||
|
||||
@@ -49,12 +49,17 @@ class RESTResponse(io.IOBase):
|
||||
self.data = self.response.data
|
||||
return self.data
|
||||
|
||||
@property
|
||||
def headers(self):
|
||||
"""Returns a dictionary of response headers."""
|
||||
return self.response.headers
|
||||
|
||||
def getheaders(self):
|
||||
"""Returns a dictionary of the response headers."""
|
||||
"""Returns a dictionary of the response headers; use ``headers`` instead."""
|
||||
return self.response.headers
|
||||
|
||||
def getheader(self, name, default=None):
|
||||
"""Returns a given response header."""
|
||||
"""Returns a given response header; use ``headers.get()`` instead."""
|
||||
return self.response.headers.get(name, default)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user