Skip to content

Commit 736bd27

Browse files
author
Duncan Harris
authored
Merge pull request #4 from pdftables/timeout
Make timeouts more explicitly configurable and supply and example
2 parents 4fbdab9 + 175e95c commit 736bd27

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,23 @@ c.xlsx('input.pdf', 'output.xlsx')
3030
## Test
3131

3232
python -m unittest test.test_pdftables_api
33+
34+
## Configuring a timeout
35+
36+
If you are converting a large document (hundreds or thousands of pages),
37+
you may want to increase the timeout.
38+
39+
Here is an example of the sort of error that might be encountered:
40+
41+
```
42+
ReadTimeout: HTTPSConnectionPool(host='pdftables.com', port=443): Read timed out. (read timeout=300)
43+
```
44+
45+
The below example allows 60 seconds to connect to our server, and 1 hour to convert the document:
46+
47+
```py
48+
import pdftables_api
49+
50+
c = pdftables_api.Client('my-api-key', timeout=(60, 3600))
51+
c.xlsx('input.pdf', 'output.xlsx')
52+
```

pdftables_api/pdftables_api.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@
4040

4141

4242
class Client(object):
43-
def __init__(self, api_key, api_url=_API_URL):
43+
def __init__(self, api_key, api_url=_API_URL, timeout=_DEFAULT_TIMEOUT):
4444
self.api_key = api_key
4545
self.api_url = api_url
46+
self.timeout = timeout
4647

4748
def xlsx(self, pdf_path, xlsx_path):
4849
"""
@@ -94,7 +95,7 @@ def dump(self, pdf_fo, out_format=None, query_params=None, **requests_params):
9495
raise APIException("Invalid API key")
9596

9697
if 'timeout' not in requests_params:
97-
requests_params.update({'timeout': _DEFAULT_TIMEOUT})
98+
requests_params.update({'timeout': self.timeout})
9899

99100
(_, out_format) = Client.ensure_format_ext(None, out_format)
100101
url = self.api_url

0 commit comments

Comments
 (0)