How to use the treq.client.HTTPClient function in treq

To help you get started, we’ve selected a few treq examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ClusterHQ / powerstrip-flocker / powerstripflocker / adapter.py View on Github external
def __init__(self, *args, **kw):
        self._agent = Agent(reactor) # no connectionpool
        self.client = HTTPClient(self._agent)
        return resource.Resource.__init__(self, *args, **kw)
github ClusterHQ / powerstrip-flocker / treq / api.py View on Github external
def _client(*args, **kwargs):
    reactor = default_reactor(kwargs.get('reactor'))
    #pool = default_pool(reactor,
    #                    kwargs.get('pool'),
    #                    kwargs.get('persistent'))

    # XXX setting pool to None is necessary to stop weird bug where deferreds
    # never fire on requests after chunked requests.
    pool = None
    agent = UNIXCapableAgent(reactor, pool=pool)
    return HTTPClient(agent)
github mochi / vor / vor / elasticsearch.py View on Github external
def __init__(self, baseURL, prefix='es', auth=None):
        """
        @param baseURL: Base URL of the ElasticSearch API, including trailing
            slash.
        """
        self.endpoint = baseURL + self.API
        self.prefix = prefix
        self.auth = auth

        self.protocol = None
        self.treq = treq.client.HTTPClient(_noVerifyAgent())
github twisted / treq / src / treq / api.py View on Github external
def _client(*args, **kwargs):
    agent = kwargs.get('agent')
    if agent is None:
        reactor = default_reactor(kwargs.get('reactor'))
        pool = default_pool(reactor,
                            kwargs.get('pool'),
                            kwargs.get('persistent'))
        agent = Agent(reactor, pool=pool)
    return HTTPClient(agent)
github ClusterHQ / powerstrip / powerstrip / powerstrip.py View on Github external
# Try to get the configuration from the default place on the
            # filesystem.
            self.config = PluginConfiguration()
        else:
            self.config = config
        self.config.read_and_parse()
        self.parser = EndpointParser(self.config)
        Resource.__init__(self)
        self.host = dockerAddr
        self.port = dockerPort
        self.socket = dockerSocket
        self.path = path
        self.reactor = reactor
        proxy.ReverseProxyResource.__init__(self, dockerAddr, dockerPort, path, reactor) # NB dockerAddr is not actually used
        self.agent = Agent(reactor) # no connectionpool
        self.client = HTTPClient(self.agent)
github cablehead / python-consul / consul / twisted.py View on Github external
def __init__(self, contextFactory, *args, **kwargs):
        super(HTTPClient, self).__init__(*args, **kwargs)
        agent_kwargs = dict(
            reactor=reactor, pool=HTTPConnectionPool(reactor))
        if contextFactory is not None:
            # use the provided context factory
            agent_kwargs['contextFactory'] = contextFactory
        elif not self.verify:
            # if no context is provided and verify is set to false, use the
            # insecure context factory implementation
            agent_kwargs['contextFactory'] = InsecureContextFactory()

        self.client = TreqHTTPClient(Agent(**agent_kwargs))
github ClusterHQ / flocker-coreos / flocker-bits / volume-cli / client.py View on Github external
if (user_crt.exists() and user_key.exists() and cluster_crt.exists()
            is not None):
        # we are installed on a flocker node with a certificate, try to reuse
        # it for auth against the control service
        cert_data = cluster_crt.getContent()
        auth_data = user_crt.getContent() + user_key.getContent()

        authority = ssl.Certificate.loadPEM(cert_data)
        client_certificate = ssl.PrivateCertificate.loadPEM(auth_data)

        class ContextFactory(object):
            def getContext(self, hostname, port):
                context = client_certificate.options(authority).getContext()
                return context

        return HTTPClient(Agent(reactor, contextFactory=ContextFactory()))
    else:
        raise Exception(
            "Not enough information to construct TLS context: "
            "user_crt: %s, cluster_crt: %s, user_key: %s" % (
                user_crt, cluster_crt, user_key
            )