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.

36 line
942 B

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