Source code for tributary.streaming.output.http

import requests
import json as JSON
from .output import _OUTPUT_GRAPHVIZSHAPE
from ..node import Node
from ...base import StreamEnd

[docs]def HTTP(node, url='', json=False, wrap=False, field=None, proxies=None, cookies=None): '''Connect to url and post results to it Args: node (Node): input tributary url (str): url to post to json (bool): dump data as json wrap (bool): wrap input in a list field (str): field to index result by proxies (list): list of URL proxies to pass to cookies (list): list of cookies to pass to ''' async def _send(data, url=url, json=json, wrap=wrap, field=field, proxies=proxies, cookies=cookies): if wrap: data = [data] if json: data = JSON.dumps(data) msg =, data=data, cookies=cookies, proxies=proxies) if msg is None: return StreamEnd() if msg.status_code != 200: return msg if json: msg = msg.json() if field: msg = msg[field] if wrap: msg = [msg] return msg ret = Node(foo=_send, name='Http', inputs=1, graphvizshape=_OUTPUT_GRAPHVIZSHAPE) node >> ret return ret