http_api.py 628 B

1234567891011121314151617181920212223242526272829
  1. # -*- coding: utf-8 -*-
  2. # @Time : 2023/7/20 16:29
  3. # @Author : XuJiakai
  4. # @File : http_api
  5. # @Software: PyCharm
  6. import json
  7. import aiohttp
  8. from data_clean.exception.fetch_exception import FetchException
  9. async def get(url: str):
  10. async with aiohttp.ClientSession() as session:
  11. async with session.get(url) as response:
  12. text = await response.text()
  13. if response.status != 200:
  14. raise FetchException(response.status, text)
  15. return text
  16. pass
  17. async def get_json(url: str):
  18. text = await get(url)
  19. return json.loads(text)
  20. if __name__ == '__main__':
  21. pass