-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding request timeout #157
base: master
Are you sure you want to change the base?
Changes from 14 commits
7dd6a4a
1d915e2
98f9ce8
83b5047
b73f4ad
545ade3
8365a37
456ed7f
1acce6a
25ac7f2
561e59a
1be8337
fd18039
eba1de2
7214851
6c762cb
ef1621d
9000528
1115d03
1280a99
c90d401
c7d57b9
0f88e26
0fcd77b
d3c35da
73b4341
81ea5bd
fd4692b
93f573c
206e2a0
5464f7a
1e465f8
7f70e5c
021e7dd
18d1824
0712ced
7523266
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
import json | ||
import requests | ||
from time import time, sleep | ||
from .errors import MatrixError, MatrixRequestError | ||
from .errors import MatrixError, MatrixRequestError, MatrixTimeoutError | ||
|
||
try: | ||
from urllib import quote | ||
|
@@ -582,16 +582,24 @@ def _send(self, method, path, content=None, query_params={}, headers={}, | |
|
||
if headers["Content-Type"] == "application/json" and content is not None: | ||
content = json.dumps(content) | ||
|
||
request_timeout = 30 + query_params.get("timeout", 30000) / 1000 | ||
|
||
response = None | ||
while True: | ||
response = requests.request( | ||
method, endpoint, | ||
params=query_params, | ||
data=content, | ||
headers=headers, | ||
verify=self.validate_cert | ||
) | ||
try: | ||
response = requests.request( | ||
method, endpoint, | ||
params=query_params, | ||
data=content, | ||
headers=headers, | ||
verify=self.validate_cert, | ||
timeout=request_timeout | ||
) | ||
except requests.exceptions.ReadTimeout: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Catch |
||
raise MatrixTimeoutError( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pass the |
||
"A timeout occured while waiting for response" | ||
) | ||
|
||
if response.status_code == 429: | ||
sleep(response.json()['retry_after_ms'] / 1000) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a new kwarg
default_timeout=25
to__init__
, and then do: