Skip to content

Commit 300de23

Browse files
committed
Make python code compatible with urllib3 v2.6.0+
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
1 parent b86213b commit 300de23

File tree

19 files changed

+63
-38
lines changed

19 files changed

+63
-38
lines changed

modules/openapi-generator/src/main/resources/python/api_client.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ class ApiClient:
321321
return_data = self.__deserialize_file(response_data)
322322
elif response_type is not None:
323323
match = None
324-
content_type = response_data.getheader('content-type')
324+
content_type = response_data.headers.get('content-type')
325325
if content_type is not None:
326326
match = re.search(r"charset=([a-zA-Z\-\d]+)[\s;]?", content_type)
327327
encoding = match.group(1) if match else "utf-8"
@@ -338,7 +338,7 @@ class ApiClient:
338338
return ApiResponse(
339339
status_code = response_data.status,
340340
data = return_data,
341-
headers = response_data.getheaders(),
341+
headers = response_data.headers,
342342
raw_data = response_data.data
343343
)
344344

@@ -719,7 +719,7 @@ class ApiClient:
719719
os.close(fd)
720720
os.remove(path)
721721

722-
content_disposition = response.getheader("Content-Disposition")
722+
content_disposition = response.headers.get("Content-Disposition")
723723
if content_disposition:
724724
m = re.search(
725725
r'filename=[\'"]?([^\'"\s]+)[\'"]?',

modules/openapi-generator/src/main/resources/python/exceptions.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class ApiException(OpenApiException):
119119
self.body = http_resp.data.decode('utf-8')
120120
except Exception:
121121
pass
122-
self.headers = http_resp.getheaders()
122+
self.headers = http_resp.headers
123123

124124
@classmethod
125125
def from_response(

modules/openapi-generator/src/main/resources/python/rest.mustache

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,17 @@ class RESTResponse(io.IOBase):
3939
self.data = self.response.data
4040
return self.data
4141

42+
@property
43+
def headers(self):
44+
"""Returns a dictionary of response headers."""
45+
return self.response.headers
46+
4247
def getheaders(self):
43-
"""Returns a dictionary of the response headers."""
48+
"""Returns a dictionary of the response headers; use ``headers`` instead."""
4449
return self.response.headers
4550

4651
def getheader(self, name, default=None):
47-
"""Returns a given response header."""
52+
"""Returns a given response header; use ``headers.get()`` instead."""
4853
return self.response.headers.get(name, default)
4954

5055

samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ def response_deserialize(
313313
return_data = self.__deserialize_file(response_data)
314314
elif response_type is not None:
315315
match = None
316-
content_type = response_data.getheader('content-type')
316+
content_type = response_data.headers.get('content-type')
317317
if content_type is not None:
318318
match = re.search(r"charset=([a-zA-Z\-\d]+)[\s;]?", content_type)
319319
encoding = match.group(1) if match else "utf-8"
@@ -330,7 +330,7 @@ def response_deserialize(
330330
return ApiResponse(
331331
status_code = response_data.status,
332332
data = return_data,
333-
headers = response_data.getheaders(),
333+
headers = response_data.headers,
334334
raw_data = response_data.data
335335
)
336336

@@ -702,7 +702,7 @@ def __deserialize_file(self, response):
702702
os.close(fd)
703703
os.remove(path)
704704

705-
content_disposition = response.getheader("Content-Disposition")
705+
content_disposition = response.headers.get("Content-Disposition")
706706
if content_disposition:
707707
m = re.search(
708708
r'filename=[\'"]?([^\'"\s]+)[\'"]?',

samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def __init__(
129129
self.body = http_resp.data.decode('utf-8')
130130
except Exception:
131131
pass
132-
self.headers = http_resp.getheaders()
132+
self.headers = http_resp.headers
133133

134134
@classmethod
135135
def from_response(

samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/rest.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,17 @@ def read(self):
4949
self.data = self.response.data
5050
return self.data
5151

52+
@property
53+
def headers(self):
54+
"""Returns a dictionary of response headers."""
55+
return self.response.headers
56+
5257
def getheaders(self):
53-
"""Returns a dictionary of the response headers."""
58+
"""Returns a dictionary of the response headers; use ``headers`` instead."""
5459
return self.response.headers
5560

5661
def getheader(self, name, default=None):
57-
"""Returns a given response header."""
62+
"""Returns a given response header; use ``headers.get()`` instead."""
5863
return self.response.headers.get(name, default)
5964

6065

samples/client/echo_api/python/openapi_client/api_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ def response_deserialize(
313313
return_data = self.__deserialize_file(response_data)
314314
elif response_type is not None:
315315
match = None
316-
content_type = response_data.getheader('content-type')
316+
content_type = response_data.headers.get('content-type')
317317
if content_type is not None:
318318
match = re.search(r"charset=([a-zA-Z\-\d]+)[\s;]?", content_type)
319319
encoding = match.group(1) if match else "utf-8"
@@ -330,7 +330,7 @@ def response_deserialize(
330330
return ApiResponse(
331331
status_code = response_data.status,
332332
data = return_data,
333-
headers = response_data.getheaders(),
333+
headers = response_data.headers,
334334
raw_data = response_data.data
335335
)
336336

@@ -702,7 +702,7 @@ def __deserialize_file(self, response):
702702
os.close(fd)
703703
os.remove(path)
704704

705-
content_disposition = response.getheader("Content-Disposition")
705+
content_disposition = response.headers.get("Content-Disposition")
706706
if content_disposition:
707707
m = re.search(
708708
r'filename=[\'"]?([^\'"\s]+)[\'"]?',

samples/client/echo_api/python/openapi_client/exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def __init__(
129129
self.body = http_resp.data.decode('utf-8')
130130
except Exception:
131131
pass
132-
self.headers = http_resp.getheaders()
132+
self.headers = http_resp.headers
133133

134134
@classmethod
135135
def from_response(

samples/client/echo_api/python/openapi_client/rest.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,17 @@ def read(self):
4949
self.data = self.response.data
5050
return self.data
5151

52+
@property
53+
def headers(self):
54+
"""Returns a dictionary of response headers."""
55+
return self.response.headers
56+
5257
def getheaders(self):
53-
"""Returns a dictionary of the response headers."""
58+
"""Returns a dictionary of the response headers; use ``headers`` instead."""
5459
return self.response.headers
5560

5661
def getheader(self, name, default=None):
57-
"""Returns a given response header."""
62+
"""Returns a given response header; use ``headers.get()`` instead."""
5863
return self.response.headers.get(name, default)
5964

6065

samples/openapi3/client/petstore/python-aiohttp/petstore_api/api_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ def response_deserialize(
315315
return_data = self.__deserialize_file(response_data)
316316
elif response_type is not None:
317317
match = None
318-
content_type = response_data.getheader('content-type')
318+
content_type = response_data.headers.get('content-type')
319319
if content_type is not None:
320320
match = re.search(r"charset=([a-zA-Z\-\d]+)[\s;]?", content_type)
321321
encoding = match.group(1) if match else "utf-8"
@@ -332,7 +332,7 @@ def response_deserialize(
332332
return ApiResponse(
333333
status_code = response_data.status,
334334
data = return_data,
335-
headers = response_data.getheaders(),
335+
headers = response_data.headers,
336336
raw_data = response_data.data
337337
)
338338

@@ -711,7 +711,7 @@ def __deserialize_file(self, response):
711711
os.close(fd)
712712
os.remove(path)
713713

714-
content_disposition = response.getheader("Content-Disposition")
714+
content_disposition = response.headers.get("Content-Disposition")
715715
if content_disposition:
716716
m = re.search(
717717
r'filename=[\'"]?([^\'"\s]+)[\'"]?',

0 commit comments

Comments
 (0)