API Reference

httsleep.httsleep(url_or_request, until=None, alarms=None, auth=None, headers=None, session=<requests.sessions.Session object>, verify=None, polling_interval=2, max_retries=50, ignore_exceptions=None, loglevel=40)

Convenience wrapper for the HttSleeper class. Creates a HttSleeper object and automatically runs it.

Returns:requests.Response object.
class httsleep.HttSleeper(url_or_request, until=None, alarms=None, auth=None, headers=None, session=<requests.sessions.Session object>, verify=None, polling_interval=2, max_retries=50, ignore_exceptions=None, loglevel=40)
Parameters:
  • url_or_request – either a string containing the URL to be polled, or a requests.Request object.
  • until – a list of success conditions, respresented by dicts, or a single success condition dict.
  • alarms – a list of error conditions, respresented by dicts, or a single error condition dict.
  • auth – a (username, password) tuple for HTTP authentication.
  • headers – a dict of HTTP headers. If specified, these will be merged with (and take precedence over) any headers provided in the session.
  • session – a Requests session, providing cookie persistence, connection-pooling, and configuration (e.g. headers).
  • verify – Either a boolean, in which case it controls whether we verify the server’s TLS certificate, or a string, in which case it must be a path to a CA bundle to use. If specified, this takes precedence over any value defined in the session (which itself would be True, by default).
  • polling_interval – how many seconds to sleep between requests.
  • max_retries – the maximum number of retries to make, after which a StopIteration exception is raised.
  • ignore_exceptions – a list of exceptions to ignore when polling the endpoint.
  • loglevel – the loglevel to use. Defaults to ERROR.

url_or_request must be provided, along with at least one success condition (until).

run()

Polls the endpoint until either:

  • a success condition in self.until is reached, in which case a requests.Request object is returned
  • an error condition in self.alarms is encountered, in which case an Alarm exception is raised
  • self.max_retries is reached, in which case a StopIteration exception is raised
Returns:requests.Response object.

Exceptions

exception httsleep.exceptions.Alarm(response, alarm_condition)

Exception raised when an alarm condition has been met. Contains the following extra attributes:

  • response: The response the matched the alarm condition
  • alarm: The alarm condition that was triggered