Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
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
def fetch (url):
r = yield from aiohttp.request ('GET', url)
print ('%s %s' % (r.status, r.reason), end = " ")
return (yield from r.read ())
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()
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))
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
def _noloop_request(method, url, headers, data=None):
response = yield from aiohttp.request(method=method, url=url,
headers=headers, data=data)
return response
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)
@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)