Skip to content

Commit 488311a

Browse files
committed
fix: url version
1 parent efed7b8 commit 488311a

8 files changed

Lines changed: 85 additions & 10 deletions

File tree

integration_test/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def campaign(self):
9494
start_time=None,
9595
end_time=None,
9696
objective_type=ObjectiveType("AWARENESS"),
97-
is_campaign_budget_optimization=False,
97+
is_campaign_budget_optimization=True,
9898
is_flexible_daily_budgets=False,
9999
default_ad_group_budget_in_micro_currency=None,
100100
is_automated_campaign=False,

openapi_generated/pinterest_client/api_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def __call_api(
221221
if response_type:
222222
if response_type != (file_type,):
223223
encoding = "utf-8"
224-
content_type = response_data.getheader('content-type')
224+
content_type = response_data.urllib3_response.headers.get('content-type')
225225
if content_type is not None:
226226
match = re.search(r"charset=([a-zA-Z\-\d]+)[\s\;]?", content_type)
227227
if match:
@@ -240,7 +240,7 @@ def __call_api(
240240
return (return_data)
241241
else:
242242
return (return_data, response_data.status,
243-
response_data.getheaders())
243+
response_data.urllib3_response.headers)
244244

245245
def parameters_to_multipart(self, params, collection_types):
246246
"""Get parameters as list of tuples, formatting as json if value is collection_types
@@ -317,7 +317,7 @@ def deserialize(self, response, response_type, _check_type):
317317
# handle file downloading
318318
# save response body into a tmp file and return the instance
319319
if response_type == (file_type,):
320-
content_disposition = response.getheader("Content-Disposition")
320+
content_disposition = response.urllib3_response.headers.get("Content-Disposition")
321321
return deserialize_file(response.data, self.configuration,
322322
content_disposition=content_disposition)
323323

openapi_generated/pinterest_client/exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def __init__(self, status=None, reason=None, http_resp=None):
104104
self.status = http_resp.status
105105
self.reason = http_resp.reason
106106
self.body = http_resp.data
107-
self.headers = http_resp.getheaders()
107+
self.headers = http_resp.urllib3_response.headers
108108
else:
109109
self.status = status
110110
self.reason = reason

openapi_generated/pinterest_client/rest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ def __init__(self, resp):
3636

3737
def getheaders(self):
3838
"""Returns a dictionary of the response headers."""
39-
return self.urllib3_response.getheaders()
39+
return self.urllib3_response.headers
4040

4141
def getheader(self, name, default=None):
4242
"""Returns a given response header."""
43-
return self.urllib3_response.getheader(name, default)
43+
return self.urllib3_response.headers.get(name, default)
4444

4545

4646
class RESTClientObject(object):

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
python_dateutil >= 2.5.3
22
setuptools >= 21.0.0
3-
urllib3 == 2.5.0
3+
urllib3>=1.26,<3

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
# http://pypi.python.org/pypi/setuptools
3232

3333
REQUIRES = [
34-
"urllib3==1.26.20",
34+
"urllib3>=1.26,<3",
3535
"python-dateutil",
3636
]
3737

spec/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ generate_client: ## Generates a python client
2626
rm -rf ../test ../.gitlab-ci.yml ../.travis.yml ../git_push.sh
2727

2828
patch_client: ## Patch the generated client
29-
@echo ====Execiting patches====
29+
@echo ====Executing patches====
3030
python ./patches/remove_bool_none_type.py
31+
python ./patches/fix_urllib3_deprecations.py
3132

3233
help: ## Show list of targets and purposes.
3334
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//'
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
"""
2+
This script fixes deprecated urllib3 methods in the generated code by replacing:
3+
- response.getheader('content-type') → response.headers.get('content-type')
4+
- response.getheaders() → response.headers
5+
6+
This addresses deprecation warnings that will become breaking errors in urllib3 2.6.0.
7+
Based on urllib3 v2.0 migration guide: https://urllib3.readthedocs.io/en/stable/v2-migration-guide.html
8+
9+
Files affected:
10+
- openapi_generated/pinterest_client/rest.py (lines 37-43)
11+
- openapi_generated/pinterest_client/api_client.py (lines 224, 243, 320)
12+
- openapi_generated/pinterest_client/exceptions.py (line 107)
13+
"""
14+
import os
15+
import re
16+
17+
directory = '../openapi_generated'
18+
19+
# Define the replacements - apply multiple times until no more changes
20+
def apply_replacements(content):
21+
"""Apply all replacements until no more changes are made"""
22+
original_content = content
23+
24+
# First: Clean up any multiple urllib3_response references (make it idempotent)
25+
content = re.sub(r'(\.urllib3_response)+', '.urllib3_response', content)
26+
27+
# Second: Replace deprecated getheader() calls with headers.get()
28+
# All response objects are RESTResponse wrappers, so use .urllib3_response.headers
29+
content = re.sub(r'(response_data|response|http_resp)\.getheader\(([^)]+)\)', r'\1.urllib3_response.headers.get(\2)', content)
30+
31+
# Third: Replace deprecated getheaders() calls with headers
32+
# All response objects are RESTResponse wrappers, so use .urllib3_response.headers
33+
content = re.sub(r'(response_data|response|http_resp)\.getheaders\(\)', r'\1.urllib3_response.headers', content)
34+
35+
return content
36+
37+
print("Starting the script to fix deprecated urllib3 methods in the 'openapi_generated' directory...")
38+
print("This ensures compatibility with both urllib3 1.x and 2.x")
39+
40+
files_modified = 0
41+
total_replacements = 0
42+
43+
for root, dirs, files in os.walk(directory):
44+
for file in files:
45+
if file.endswith(".py"):
46+
file_path = os.path.join(root, file)
47+
48+
try:
49+
with open(file_path, 'r', encoding='utf-8') as f:
50+
content = f.read()
51+
52+
original_content = content
53+
54+
# Apply all replacements using the function
55+
content = apply_replacements(content)
56+
57+
# Write back if changes were made
58+
if content != original_content:
59+
with open(file_path, 'w', encoding='utf-8') as f:
60+
f.write(content)
61+
62+
# Count replacements made in this file
63+
file_replacements = len(original_content) - len(content) + content.count('urllib3_response') - original_content.count('urllib3_response')
64+
65+
print(f"Modified: {file_path} ({file_replacements} replacements)")
66+
files_modified += 1
67+
total_replacements += file_replacements
68+
69+
except Exception as e:
70+
print(f"Error processing {file_path}: {e}")
71+
72+
print(f"Script completed. Modified {files_modified} files with {total_replacements} total replacements.")
73+
print("Deprecated urllib3 methods have been updated to use the new headers API.")
74+
print("Your package now supports both urllib3 1.x and 2.x!")

0 commit comments

Comments
 (0)