How to use the treq.get 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 leapcode / soledad / tests / server / test_tac.py View on Github external
def _get(self, *args, **kwargs):
        kwargs['agent'] = Agent(reactor)
        return treq.get(*args, **kwargs)
github rackerlabs / otter / scripts / worker_tenants.py View on Github external
def get_tenant_ids(token, catalog):
    endpoint = public_endpoint_url(catalog, "cloudMetrics", "IAD")
    d = treq.get(
        append_segments(endpoint, "metrics", "search"),
        headers=headers(token), params={"query": "*.*.desired"})
    d.addCallback(check_success, [200])
    d.addCallback(treq.json_content)
    d.addCallback(lambda body: [item["metric"].split(".")[1] for item in body])
    return d
github gridsync / gridsync / gridsync / setup.py View on Github external
def fetch_icon(self, url, dest):
        agent = None
        if self.use_tor:
            tor = yield get_tor(reactor)
            if not tor:
                raise TorError("Could not connect to a running Tor daemon")
            agent = tor.web_agent()
        resp = yield treq.get(url, agent=agent)
        if resp.code == 200:
            content = yield treq.content(resp)
            log.debug("Received %i bytes", len(content))
            with atomic_write(dest, mode="wb", overwrite=True) as f:
                f.write(content)
            self.got_icon.emit(dest)
        else:
            log.warning("Error fetching service icon: %i", resp.code)
github knowitnothing / btcx / btcx / http.py View on Github external
def http_call(self, urlpart, cb, **kwargs):
        headers = Headers({"User-Agent": [USER_AGENT]})
        d = treq.get('%s/%s' % (self.host, urlpart),
                params=kwargs, headers=headers)
        d.addCallback(lambda response: self.decode_or_error(
            response, cb, urlpart, **kwargs))
github CPChain / pdash / cpchain / storage_plugin / proxy.py View on Github external
def download_data(self, src, dst):

        f = open(dst, 'wb')
        resp = yield treq.get(src, agent=no_verify_agent())
        yield treq.collect(resp, f.write)
        f.close()
github crossbario / crossbar / crossbar / webservice / archive.py View on Github external
def _download(reactor, url, destination_filename):
    destination = open(destination_filename, 'wb')
    d = treq.get(url)
    d.addCallback(treq.collect, destination.write)
    d.addBoth(lambda _: destination.close())
    return d
github twisted / treq / docs / _examples / download_file.py View on Github external
def download_file(url, destination):
    d = treq.get(url)
    d.addCallback(treq.collect, destination.write)
    d.addBoth(destination.close)
    return d
github yeraydiazdiaz / asyncio-ftwpd / twisted / 1d-async-fetch-from-server-twisted.py View on Github external
async def fetch_async(pid):
    print('Fetch async process {} started'.format(pid))
    start = time.time()
    response = await treq.get(URL)
    # unfortunately Twisted's Agent which treq is base on does not expose
    # connection headers so we cannot get the Date header in the same way
    # https://github.com/twisted/treq/issues/56#issuecomment-36573795
    content_type = response.headers.getRawHeaders('Content-Type', '')

    print('Process {}: {}, took: {:.2f} seconds'.format(
        pid, content_type, time.time() - start))

    return datetime
github lbryio / lbry-sdk / lbrynet / daemon / ExchangeRateManager.py View on Github external
def _make_request(self):
        response = yield treq.get(self.url, params=self.params, timeout=self.REQUESTS_TIMEOUT)
        defer.returnValue((yield response.content()))
github UltrosBot / Ultros-contrib / xkcd / plugins / xkcd / __init__.py View on Github external
def get_comic_by_id(self, comic_id):
        """
        Returns the info for the given comic
        :param url: Comic ID number
        :return: Deferred that fires with a dict of info
        """
        self.logger.debug("Getting comic by ID")
        if comic_id in self._comic_cache:
            return defer.succeed(dict(self._comic_cache[comic_id]))
        else:
            d = treq.get("http://xkcd.com/%s/info.0.json" % comic_id)
            d.addCallbacks(self._get_comic_result,
                           self._get_comic_error,
                           [comic_id])
            return d