Vous ne pouvez pas sélectionner plus de 25 sujets
Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
34 lignes
874 B
34 lignes
874 B
import asyncio
|
|
import aiohttp
|
|
|
|
|
|
async def get_root(client):
|
|
async with client.get('http://localhost/') as resp:
|
|
assert resp.status == 200
|
|
return await resp.json()
|
|
|
|
|
|
async def main():
|
|
unix_conn = aiohttp.UnixConnector(path='./input.sock')
|
|
|
|
try:
|
|
async with aiohttp.ClientSession(connector=unix_conn) as client:
|
|
print('---------------------------')
|
|
print('Request GET "/" HTTP/1.1:')
|
|
response = await get_root(client)
|
|
print(f'Response: {response}')
|
|
print('---------------------------')
|
|
except KeyboardInterrupt:
|
|
raise
|
|
finally:
|
|
print('\nClosing connection...')
|
|
await unix_conn.close()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
loop = asyncio.new_event_loop()
|
|
try:
|
|
loop.run_until_complete(main())
|
|
except KeyboardInterrupt:
|
|
loop.close()
|