Skip to content

Commit

Permalink
default timeout for requests (openWB#1778)
Browse files Browse the repository at this point in the history
  • Loading branch information
LKuemmel authored Aug 12, 2024
1 parent 2d5a995 commit 88edf35
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions packages/modules/common/req.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,18 @@
log = logging.getLogger(__name__)


def get_http_session() -> Session:
session = Session()
class CustomSession(Session):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.default_timeout = 5

def request(self, method, url, *args, **kwargs):
kwargs.setdefault('timeout', self.default_timeout)
return super().request(method, url, *args, **kwargs)


def get_http_session() -> CustomSession:
session = CustomSession()
session.hooks['response'].append(lambda r, *args, **kwargs: r.raise_for_status())
session.hooks['response'].append(lambda r, *args, **kwargs: log.debug("Get-Response: " + r.text))
return session

0 comments on commit 88edf35

Please sign in to comment.