-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
define http-request-timeouts (+ refactor)
As suggested by `requests`'s documentation [0], define time-outs for http-requests. This change was inspired/suggested by bandit [1][2]. This change addresses all findings of `medium` severity. In addition, switch to using `requests.sessions.Session` where reasonable (this is the case if there is a reasonable likelihood for a session to actually be used more than once). Also, refactor some quirky code. Considerations w.r.t. redundantly defining timeout parameter ------------------------------------------------------------ As discussed on `requests`'s GitHub-Repository (e.g. at [3]), there is no means (except, of course, through "monkey-patching") to define a default timeout, neither globally, nor e.g. for a session. While it is an option to implement a custom transport-adaptor (and use it to inject timeout parameter into issued requests), this approach seems rather heavyweight, and will add a lot of boilerplate code. Therefore, it seems like the best available option to pass `timeout` parameter to each individual invocation of `requests`'s "request-issueing-functions" (request, get, put, ...). One might feel the urge to deduplicate the specified timeout values. However, there are reasons against this: - will also add boilerplate (one extra import stmt) - it is unlikely that timeouts will ever (have to) be changed (more likely: specific individual timeouts might require "tuning" - which is very easy with the chosen approach) Therefore - assuming the chosen de-facto default timeout value proves to be "good enough" - it seems like an adequate choice to redundantly define timeout values. [0] https://requests.readthedocs.io/en/latest/user/advanced/#timeouts [1] https://bandit.readthedocs.io/en/1.7.6/plugins/b113_request_without_timeout.html [2] https://bandit.readthedocs.io/ [3] psf/requests#3070
- Loading branch information
Showing
12 changed files
with
143 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.