Use proper timeouts for requests + better error handling
Default behaviour apparently is blocking, we never want that! Also make error responses actually raise an exception.
This commit is contained in:
parent
9bcce4e56a
commit
bba9d6cc18
6 changed files with 11 additions and 8 deletions
|
|
@ -324,7 +324,8 @@ class AnnouncementPlugin(octoprint.plugin.AssetPlugin,
|
|||
url = config["url"]
|
||||
try:
|
||||
start = time.time()
|
||||
r = requests.get(url)
|
||||
r = requests.get(url, timeout=30)
|
||||
r.raise_for_status()
|
||||
self._logger.info(u"Loaded channel {} from {} in {:.2}s".format(key, config["url"], time.time() - start))
|
||||
except Exception as e:
|
||||
self._logger.exception(
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin,
|
|||
|
||||
##~~ StartupPlugin
|
||||
|
||||
def on_startup(self, host, port):
|
||||
def on_after_startup(self):
|
||||
from octoprint.logging.handlers import CleaningTimedRotatingFileHandler
|
||||
console_logging_handler = CleaningTimedRotatingFileHandler(self._settings.get_plugin_logfile_path(postfix="console"), when="D", backupCount=3)
|
||||
console_logging_handler.setFormatter(logging.Formatter("%(asctime)s %(message)s"))
|
||||
|
|
@ -676,7 +676,8 @@ class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin,
|
|||
def _fetch_repository_from_url(self):
|
||||
repository_url = self._settings.get(["repository"])
|
||||
try:
|
||||
r = requests.get(repository_url)
|
||||
r = requests.get(repository_url, timeout=30)
|
||||
r.raise_for_status()
|
||||
self._logger.info("Loaded plugin repository data from {}".format(repository_url))
|
||||
except Exception as e:
|
||||
self._logger.exception("Could not fetch plugins from repository at {repository_url}: {message}".format(repository_url=repository_url, message=str(e)))
|
||||
|
|
@ -744,7 +745,8 @@ class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin,
|
|||
def _fetch_notices_from_url(self):
|
||||
notices_url = self._settings.get(["notices"])
|
||||
try:
|
||||
r = requests.get(notices_url)
|
||||
r = requests.get(notices_url, timeout=30)
|
||||
r.raise_for_status()
|
||||
self._logger.info("Loaded plugin notices data from {}".format(notices_url))
|
||||
except Exception as e:
|
||||
self._logger.exception("Could not fetch notices from {notices_url}: {message}".format(notices_url=notices_url, message=str(e)))
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ BRANCH_HEAD_URL = "https://api.github.com/repos/{user}/{repo}/git/refs/heads/{br
|
|||
logger = logging.getLogger("octoprint.plugins.softwareupdate.version_checks.github_commit")
|
||||
|
||||
def _get_latest_commit(user, repo, branch):
|
||||
r = requests.get(BRANCH_HEAD_URL.format(user=user, repo=repo, branch=branch))
|
||||
r = requests.get(BRANCH_HEAD_URL.format(user=user, repo=repo, branch=branch), timeout=30)
|
||||
|
||||
from . import log_github_ratelimit
|
||||
log_github_ratelimit(logger, r)
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ def _get_latest_release(user, repo, compare_type,
|
|||
prerelease_channel=None,
|
||||
force_base=True):
|
||||
nothing = None, None, None
|
||||
r = requests.get(RELEASE_URL.format(user=user, repo=repo))
|
||||
r = requests.get(RELEASE_URL.format(user=user, repo=repo), timeout=30)
|
||||
|
||||
from . import log_github_ratelimit
|
||||
log_github_ratelimit(logger, r)
|
||||
|
|
|
|||
|
|
@ -556,7 +556,7 @@ class Timelapse(object):
|
|||
eventManager().fire(Events.CAPTURE_START, dict(file=filename))
|
||||
try:
|
||||
self._logger.debug("Going to capture {} from {}".format(filename, self._snapshot_url))
|
||||
r = requests.get(self._snapshot_url, stream=True)
|
||||
r = requests.get(self._snapshot_url, stream=True, timeout=5)
|
||||
r.raise_for_status()
|
||||
|
||||
with open (filename, "wb") as f:
|
||||
|
|
|
|||
|
|
@ -231,7 +231,7 @@ class Client(object):
|
|||
request.prepare_body(None, None, json=data)
|
||||
else:
|
||||
request.prepare_body(data, files=files)
|
||||
response = s.send(request)
|
||||
response = s.send(request, timeout=10)
|
||||
return response
|
||||
|
||||
def get(self, path, params=None):
|
||||
|
|
|
|||
Loading…
Reference in a new issue