thorn.request — Thorn 1.3.0 documentation

# thorn.request

- thorn.webhook.request

## thorn.webhook.request

Webhook HTTP requests.

class `thorn.request.` `Request`(event, data, sender, subscriber, id=None, on_success=None, on_error=None, timeout=None, on_timeout=None, retry=None, retry_max=None, retry_delay=None, headers=None, user_agent=None, app=None, recipient_validators=None, allow_keepalive=True)

  Webhook HTTP request

  Parameters: | event – Name of event. data – Event payload. sender – Sender of event (or `None`). subscriber – Subscriber to dispatch the request for. on_success – Optional callback called if the HTTP request succeeds. Must take single argument: `request`. on_timeout – Optional callback called if the HTTP request times out. Must have signature: `(request, exc)`. on_error – Optional callback called if the HTTP request fails. Must have signature: `(request, exc)`. headers – Additional HTTP headers to send with the request. user_agent – Set custom HTTP user agent. recipient_validators – List of serialized recipient validators. allow_keepalive – Allow reusing session for this HTTP request. Enabled by default. retry – Retry in the event of timeout/failure? Disabled by default. retry_max – Maximum number of times to retry before giving up. Default is 3. retry_delay – Delay between retries in seconds int/float. Default is 60 seconds.

  class `Session`

    A Requests session.

    Provides cookie persistence, connection-pooling, and configuration.

    Basic Usage:

        >>> import requests
        >>> s = requests.Session()
        >>> s.get('http://httpbin.org/get')
        <Response [200]>

    Or as a context manager:

        >>> with requests.Session() as s:
        >>>     s.get('http://httpbin.org/get')
        <Response [200]>

    `close`()

      Closes all adapters and as such the session

    `delete`(url, **kwargs)

      Sends a DELETE request. Returns `Response` object.

      Parameters: | url – URL for the new `Request` object. **kwargs – Optional arguments that `request` takes.

    `get`(url, **kwargs)

      Sends a GET request. Returns `Response` object.

      Parameters: | url – URL for the new `Request` object. **kwargs – Optional arguments that `request` takes.

    `get_adapter`(url)

      Returns the appropriate connection adapter for the given URL.

    `head`(url, **kwargs)

      Sends a HEAD request. Returns `Response` object.

      Parameters: | url – URL for the new `Request` object. **kwargs – Optional arguments that `request` takes.

    `merge_environment_settings`(url, proxies, stream, verify, cert)

      Check the environment and merge it with some settings.

    `mount`(prefix, adapter)

      Registers a connection adapter to a prefix.

      Adapters are sorted in descending order by key length.

    `options`(url, **kwargs)

      Sends a OPTIONS request. Returns `Response` object.

      Parameters: | url – URL for the new `Request` object. **kwargs – Optional arguments that `request` takes.

    `patch`(url, data=None, **kwargs)

      Sends a PATCH request. Returns `Response` object.

      Parameters: | url – URL for the new `Request` object. data – (optional) Dictionary, bytes, or file-like object to send in the body of the `Request`. **kwargs – Optional arguments that `request` takes.

    `post`(url, data=None, json=None, **kwargs)

      Sends a POST request. Returns `Response` object.

      Parameters: | url – URL for the new `Request` object. data – (optional) Dictionary, bytes, or file-like object to send in the body of the `Request`. json – (optional) json to send in the body of the `Request`. **kwargs – Optional arguments that `request` takes.

    `prepare_request`(request)

      Constructs a `PreparedRequest` for transmission and returns it. The `PreparedRequest` has settings merged from the `Request` instance and those of the `Session`.

      Parameters: | request – `Request` instance to prepare with this session’s settings.

    `put`(url, data=None, **kwargs)

      Sends a PUT request. Returns `Response` object.

      Parameters: | url – URL for the new `Request` object. data – (optional) Dictionary, bytes, or file-like object to send in the body of the `Request`. **kwargs – Optional arguments that `request` takes.

    `request`(method, url, params=None, data=None, headers=None, cookies=None, files=None, auth=None, timeout=None, allow_redirects=True, proxies=None, hooks=None, stream=None, verify=None, cert=None, json=None)

      Constructs a `Request`, prepares it and sends it. Returns `Response` object.

      Parameters: | method – method for the new `Request` object. url – URL for the new `Request` object. params – (optional) Dictionary or bytes to be sent in the query string for the `Request`. data – (optional) Dictionary, bytes, or file-like object to send in the body of the `Request`. json – (optional) json to send in the body of the `Request`. headers – (optional) Dictionary of HTTP Headers to send with the `Request`. cookies – (optional) Dict or CookieJar object to send with the `Request`. files – (optional) Dictionary of `'filename': file-like-objects` for multipart encoding upload. auth – (optional) Auth tuple or callable to enable Basic/Digest/Custom HTTP Auth. timeout (float or tuple) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) tuple. allow_redirects (bool) – (optional) Set to True by default. proxies – (optional) Dictionary mapping protocol or protocol and hostname to the URL of the proxy. stream – (optional) whether to immediately download the response content. Defaults to `False`. verify – (optional) whether the SSL cert will be verified. A CA_BUNDLE path can also be provided. Defaults to `True`. cert – (optional) if String, path to ssl client cert file (.pem). If Tuple, (‘cert’, ‘key’) pair.
      Return type: | requests.Response

    `send`(request, **kwargs)

      Send a given PreparedRequest.

  `Request.` `annotate_headers`(extra_headers)
  `Request.` `app` = None
  `Request.` `as_dict`()

    Return a dictionary representation of this request suitable for serialization.

  `Request.` `connection_errors` = (<class 'requests.exceptions.ConnectionError'>,)

    Tuple of exceptions considered a connection error.

  `Request.` `default_headers`
  `Request.` `dispatch`(session=None, propagate=False, close_session=False)
  `Request.` `handle_connection_error`(exc, propagate=False)
  `Request.` `handle_timeout_error`(exc, propagate=False)
  `Request.` `headers`
  `Request.` `recipient_validators`
  `Request.` `response` = None

    Holds the response after the HTTP request is performed.

  `Request.` `sign_request`(subscriber, data)
  `Request.` `timeout_errors` = (<class 'requests.exceptions.Timeout'>,)

    Tuple of exceptions considered a timeout error.

  `Request.` `urlident`

    Used to order HTTP requests by URL.

  `Request.` `user_agent` = u'Mozilla/5.0 (compatible; thorn/1.3.0; python-requests/2.10.0)'

    HTTP User-Agent header.

  `Request.` `validate_recipient`(url)
  `Request.` `value`