How to use the aiohttp.request function in aiohttp

To help you get started, we’ve selected a few aiohttp 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 GNS3 / gns3-server / tests / handlers / api / compute / test_file.py View on Github external
def go(future):
        query = json.dumps({"location": str(tmpdir / "test")})
        headers = {'content-type': 'application/json'}
        response = yield from aiohttp.request("GET", http_compute.get_url("/files/stream"), data=query, headers=headers)
        response.body = yield from response.content.read(5)
        with open(str(tmpdir / "test"), 'a') as f:
            f.write("world")
        response.body += yield from response.content.read(5)
        response.close()
        future.set_result(response)
github aio-libs / aiohttp / tests / test_client_functional.py View on Github external
async def test_aiohttp_request_ctx_manager_not_found() -> None:

    with pytest.raises(aiohttp.ClientConnectionError):
        async with aiohttp.request('GET', 'http://wrong-dns-name.com'):
            assert False, "never executed"  # pragma: no cover
github hansroh / aquests / tests / test_get_all_static_aiohttp.py View on Github external
def fetch (url):
	r = yield from aiohttp.request ('GET', url)
	print ('%s %s' % (r.status, r.reason), end = " ")
	return (yield from r.read ())
github bslatkin / pycon2014 / e06asyncextract.py View on Github external
def fetch_async(url):
    logging.info('Fetching %s', url)
    response = yield from aiohttp.request('get', url, timeout=5)
    try:
        assert response.status == 200
        data = yield from response.read()
        assert data
        return data.decode('utf-8')
    finally:
        response.close()
github CenterForOpenScience / waterbutler / waterbutler / providers / osfstorage / tasks / utils.py View on Github external
async def push_metadata(version_id, callback_url, metadata):
    signer = signing.Signer(settings.HMAC_SECRET, settings.HMAC_ALGORITHM)
    data = signing.sign_data(
        signer,
        {
            'version': version_id,
            'metadata': metadata,
        },
    )
    response = await aiohttp.request(
        'PUT',
        callback_url,
        data=json.dumps(data),
        headers={'Content-Type': 'application/json'},
    )

    if response.status != HTTPStatus.OK:
        raise Exception('Failed to report archive completion, got status '
                        'code {}'.format(response.status))
github Xinkai / XwareDesktop / src / frontend / libxware / vanilla.py View on Github external
def get(self, path, params = None, data = None):
        self._readyCheck()
        res = yield from aiohttp.request(
            "GET",
            "http://{host}:{port}/{path}".format(
                host = self._options["host"], port = self._options["port"], path = path),
            connector = self._connector,
            params = params,
            data = data,
        )
        if not res.status == 200:
            raise ValueError("response status is not 200", res.status)
        body = yield from res.read()
        return body
github rackerlabs / deuce / deuce / util / client.py View on Github external
def _noloop_request(method, url, headers, data=None):
    response = yield from aiohttp.request(method=method, url=url,
                                          headers=headers, data=data)
    return response
github Eyepea / API-Hour / examples / hello_world.py View on Github external
def query():
        resp = yield from aiohttp.request(
            'GET', 'http://127.0.0.1:8080/hello-world',
            loop=loop)
        json_data = yield from resp.json()
        print(json_data)

        name = os.environ.get('USER', 'John')
        resp = yield from aiohttp.request(
            'GET', 'http://127.0.0.1:8080/hello/{}'.format(name))

        json_data = yield from resp.json()
        print(json_data)
github fluentpython / example-code / attic / concurrency / wikipedia / daypicts_asyncio.py View on Github external
@asyncio.coroutine
def get_picture_url(iso_date, semaphore):
    page_url = POTD_BASE_URL+iso_date
    with (yield from semaphore):
        response = yield from aiohttp.request('GET', page_url)
        text = yield from response.text()
    pict_url = POTD_IMAGE_RE.search(text)
    if pict_url is None:
        raise NoPictureForDate(iso_date)
    return 'http:' + pict_url.group(1)