You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
874 B

  1. import asyncio
  2. import aiohttp
  3. async def get_root(client):
  4. async with client.get('http://localhost/') as resp:
  5. assert resp.status == 200
  6. return await resp.json()
  7. async def main():
  8. unix_conn = aiohttp.UnixConnector(path='./input.sock')
  9. try:
  10. async with aiohttp.ClientSession(connector=unix_conn) as client:
  11. print('---------------------------')
  12. print('Request GET "/" HTTP/1.1:')
  13. response = await get_root(client)
  14. print(f'Response: {response}')
  15. print('---------------------------')
  16. except KeyboardInterrupt:
  17. raise
  18. finally:
  19. print('\nClosing connection...')
  20. await unix_conn.close()
  21. if __name__ == '__main__':
  22. loop = asyncio.new_event_loop()
  23. try:
  24. loop.run_until_complete(main())
  25. except KeyboardInterrupt:
  26. loop.close()