Skip to content

Commit 51b65fe

Browse files
author
jm
committed
add timeout
1 parent e1c05a9 commit 51b65fe

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

dspace_rest_client/client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def api_get(self, url, params=None, data=None, headers=None):
218218
self.update_token(r)
219219
return r
220220

221-
def api_post(self, url, params, json, retry=False):
221+
def api_post(self, url, params, json, retry=False, timeout=None):
222222
"""
223223
Perform a POST request. Refresh XSRF token if necessary.
224224
POSTs are typically used to create objects.
@@ -230,7 +230,7 @@ def api_post(self, url, params, json, retry=False):
230230
"""
231231
self._last_err = None
232232
r = self.session.post(url, json=json, params=params, headers=self.request_headers,
233-
proxies=self.proxies)
233+
proxies=self.proxies, timeout=timeout)
234234
self.update_token(r)
235235

236236
if r.status_code == 403:
@@ -244,7 +244,7 @@ def api_post(self, url, params, json, retry=False):
244244
_logger.warning(f'Too many retries updating token: {r.status_code}: {r.text}')
245245
else:
246246
_logger.debug("Retrying request with updated CSRF token")
247-
return self.api_post(url, params=params, json=json, retry=True)
247+
return self.api_post(url, params=params, json=json, retry=True, timeout=timeout)
248248

249249
# we need to log in again, if there is login error. This is a bad
250250
# solution copied from the past
@@ -260,7 +260,7 @@ def api_post(self, url, params, json, retry=False):
260260
self.authenticate()
261261
# Try to authenticate and repeat the request 3 times -
262262
# if it won't happen log error
263-
return self.api_post(url, params=params, json=json, retry=False)
263+
return self.api_post(url, params=params, json=json, retry=False, timeout=timeout)
264264
return r
265265

266266
def api_post_uri(self, url, params, uri_list, retry=False):

0 commit comments

Comments
 (0)