@@ -40,6 +40,7 @@ def __init__(
4040 application_name : str | None = None ,
4141 application_version : str | None = None ,
4242 poll_interval : int = 1 ,
43+ timeout : float | tuple [float , float ] | None = None ,
4344 ):
4445 """Create an new Client instance
4546
@@ -48,12 +49,14 @@ def __init__(
4849 :param application_name: Your application name
4950 :param application_version: Your application _version
5051 :param poll_interval: Interval for polling information from Hetzner Cloud API in seconds
52+ :param timeout: Requests timeout in seconds
5153 """
5254 self .token = token
5355 self ._api_endpoint = api_endpoint
5456 self ._application_name = application_name
5557 self ._application_version = application_version
5658 self ._requests_session = requests .Session ()
59+ self ._requests_timeout = timeout
5760 self .poll_interval = poll_interval
5861
5962 self .datacenters = DatacentersClient (self )
@@ -194,12 +197,16 @@ def request( # type: ignore[no-untyped-def]
194197 :param method: HTTP Method to perform the Request
195198 :param url: URL of the Endpoint
196199 :param tries: Tries of the request (used internally, should not be set by the user)
200+ :param timeout: Requests timeout in seconds
197201 :return: Response
198202 """
203+ timeout = kwargs .pop ("timeout" , self ._requests_timeout )
204+
199205 response = self ._requests_session .request (
200206 method = method ,
201207 url = self ._api_endpoint + url ,
202208 headers = self ._get_headers (),
209+ timeout = timeout ,
203210 ** kwargs ,
204211 )
205212
@@ -217,8 +224,8 @@ def request( # type: ignore[no-untyped-def]
217224 time .sleep (tries * self ._retry_wait_time )
218225 tries = tries + 1
219226 return self .request (method , url , tries , ** kwargs )
220- else :
221- self ._raise_exception_from_content (content )
227+
228+ self ._raise_exception_from_content (content )
222229 else :
223230 self ._raise_exception_from_response (response )
224231
0 commit comments