Skip to content

Commit 834d9de

Browse files
committed
option to pass timeout directly to server instance
1 parent e40d204 commit 834d9de

3 files changed

Lines changed: 15 additions & 5 deletions

File tree

fmrest/server.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
import requests
88
from .utils import (request, build_portal_params, build_script_params,
99
filename_from_url, PlaceholderDict)
10-
from .const import (PORTAL_PREFIX, FMSErrorCode, API_VERSIONS, API_DATE_FORMATS, API_PATH_PREFIX,
11-
API_PATH)
10+
from .const import (PORTAL_PREFIX, FMSErrorCode, API_VERSIONS,
11+
API_DATE_FORMATS, API_PATH_PREFIX,
12+
API_PATH, TIMEOUT)
1213
from .exceptions import BadJSON, FileMakerError, RecordError, BadGatewayError
1314
from .record import Record
1415
from .foundset import Foundset
@@ -45,7 +46,8 @@ def __init__(self, url: str, user: str,
4546
type_conversion: bool = False,
4647
auto_relogin: bool = False,
4748
proxies: Optional[Dict] = None,
48-
api_version: Optional[str] = None) -> None:
49+
api_version: Optional[str] = None,
50+
timeout: int = TIMEOUT) -> None:
4951
"""Initialize the Server class.
5052
5153
Parameters
@@ -93,6 +95,10 @@ def __init__(self, url: str, user: str,
9395
Configure which version of the data API should be queried (e.g. v1)
9496
It is recommended to set the version explicitly to prevent
9597
potential future breaking changes.
98+
timeout : int
99+
Duration in seconds to wait for FMS to respond (HTTP timeout).
100+
This takes priority over the legacy environment variable
101+
"fmrest_timeout".
96102
"""
97103

98104
self.url = url
@@ -104,6 +110,7 @@ def __init__(self, url: str, user: str,
104110
self.verify_ssl = verify_ssl
105111
self.auto_relogin = auto_relogin
106112
self.proxies = proxies
113+
self.timeout = timeout
107114

108115
if not api_version:
109116
warnings.warn('No api_version given. Defaulting to v1.')
@@ -701,6 +708,7 @@ def fetch_file(self, file_url: str,
701708
url=file_url,
702709
verify=self.verify_ssl,
703710
stream=stream,
711+
timeout=self.timeout,
704712
proxies=self.proxies)
705713

706714
return (name,
@@ -920,6 +928,7 @@ def _call_filemaker(self, method: str, path: str,
920928
verify=self.verify_ssl,
921929
params=params,
922930
proxies=self.proxies,
931+
timeout=self.timeout,
923932
**kwargs)
924933

925934
if response.status_code == 502:

fmrest/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77

88
def request(*args, **kwargs) -> requests.Response:
99
"""Wrapper around requests library request call"""
10+
timeout = kwargs.pop("timeout", TIMEOUT)
1011
try:
11-
return requests.request(*args, timeout=TIMEOUT, **kwargs)
12+
return requests.request(*args, timeout=timeout, **kwargs)
1213
except Exception as ex:
1314
raise RequestException(ex, args, kwargs) from None
1415

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup(
77
name='python-fmrest',
8-
version='1.7.2',
8+
version='1.7.3',
99
python_requires='>=3.6',
1010
author='David Hamann',
1111
author_email='dh@davidhamann.de',

0 commit comments

Comments
 (0)