thorn.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)[source]¶ 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
Responseobject.Parameters: - url – URL for the new
Requestobject. - **kwargs – Optional arguments that
requesttakes.
- url – URL for the new
-
get(url, **kwargs)¶ Sends a GET request. Returns
Responseobject.Parameters: - url – URL for the new
Requestobject. - **kwargs – Optional arguments that
requesttakes.
- url – URL for the new
-
get_adapter(url)¶ Returns the appropriate connection adapter for the given URL.
-
head(url, **kwargs)¶ Sends a HEAD request. Returns
Responseobject.Parameters: - url – URL for the new
Requestobject. - **kwargs – Optional arguments that
requesttakes.
- url – URL for the new
-
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
Responseobject.Parameters: - url – URL for the new
Requestobject. - **kwargs – Optional arguments that
requesttakes.
- url – URL for the new
-
patch(url, data=None, **kwargs)¶ Sends a PATCH request. Returns
Responseobject.Parameters:
-
post(url, data=None, json=None, **kwargs)¶ Sends a POST request. Returns
Responseobject.Parameters:
-
prepare_request(request)¶ Constructs a
PreparedRequestfor transmission and returns it. ThePreparedRequesthas settings merged from theRequestinstance and those of theSession.Parameters: request – Requestinstance to prepare with this session’s settings.
-
put(url, data=None, **kwargs)¶ Sends a PUT request. Returns
Responseobject.Parameters:
-
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. ReturnsResponseobject.Parameters: - method – method for the new
Requestobject. - url – URL for the new
Requestobject. - 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-objectsfor 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: - method – method for the new
-
send(request, **kwargs)¶ Send a given PreparedRequest.
-
-
Request.app= None¶
-
Request.as_dict()[source]¶ 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.response= None¶ Holds the response after the HTTP request is performed.
-
Request.timeout_errors= (<class 'requests.exceptions.Timeout'>,)¶ Tuple of exceptions considered a timeout error.
-
Request.user_agent= u'Mozilla/5.0 (compatible; thorn/1.3.0; python-requests/2.10.0)'¶ HTTP User-Agent header.
-
Request.value¶