Skip to content

Commit 781d4f4

Browse files
author
Vadim Torchin
committed
fix: use timeouts in REST clients
1 parent 1fe22db commit 781d4f4

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

languages/python/templates/rest.mustache

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,15 @@ class RESTClientObject:
104104
url,
105105
data=request_body,
106106
headers=headers,
107+
timeout=_request_timeout,
107108
)
108109
elif content_type == 'application/x-www-form-urlencoded':
109110
r = self.session.request(
110111
method,
111112
url,
112113
params=post_params,
113114
headers=headers,
115+
timeout=_request_timeout,
114116
)
115117
elif content_type == 'multipart/form-data':
116118
# must del headers['Content-Type'], or the correct
@@ -124,6 +126,7 @@ class RESTClientObject:
124126
url,
125127
files=post_params,
126128
headers=headers,
129+
timeout=_request_timeout,
127130
)
128131
# Pass a `string` parameter directly in the body to support
129132
# other content types than JSON when `body` argument is
@@ -134,14 +137,17 @@ class RESTClientObject:
134137
url,
135138
data=body,
136139
headers=headers,
140+
timeout=_request_timeout,
137141
)
138142
elif headers['Content-Type'].startswith('text/') and isinstance(body, bool):
139143
request_body = "true" if body else "false"
140144
r = self.session.request(
141145
method,
142146
url,
143147
data=request_body,
144-
headers=headers)
148+
headers=headers,
149+
timeout=_request_timeout,
150+
)
145151
else:
146152
# Cannot generate the request from given parameters
147153
msg = """Cannot prepare a request message for provided
@@ -155,6 +161,7 @@ class RESTClientObject:
155161
url,
156162
params={},
157163
headers=headers,
164+
timeout=_request_timeout,
158165
)
159166
except requests.exceptions.SSLError as e:
160167
msg = "\n".join([type(e).__name__, str(e)])

0 commit comments

Comments
 (0)