123456789101112131415161718192021222324252627282930313233343536 |
- # -*- coding: utf-8 -*-
- # @Time : 2023/7/20 16:29
- # @Author : XuJiakai
- # @File : http_api
- # @Software: PyCharm
- import aiohttp
- from data_clean.exception.fetch_exception import FetchException
- async def get(url: str, result_json: bool = True):
- async with aiohttp.ClientSession() as session:
- async with session.get(url) as response:
- if result_json:
- result = await response.json()
- else:
- result = await response.text()
- if response.status != 200:
- raise FetchException(response.status, result)
- return result
- pass
- async def post(url: str, data: dict):
- async with aiohttp.ClientSession() as session:
- async with session.post(url, json=data) as response:
- result = await response.json()
- if response.status != 200:
- raise FetchException(response.status, result)
- return result
- pass
- if __name__ == '__main__':
- pass
|