summaryrefslogtreecommitdiff
path: root/ATRI/utils
diff options
context:
space:
mode:
authorKyomotoi <[email protected]>2021-10-01 08:56:42 +0800
committerKyomotoi <[email protected]>2021-10-01 08:56:42 +0800
commit844bd56a5bed1293329299c8b0562558a0d2d907 (patch)
tree0b121b4e85b42e9a83dd65639013215272bb6527 /ATRI/utils
parenta00308d801a0ce13f0f19f6c3984bbbe2e09f57b (diff)
downloadATRI-844bd56a5bed1293329299c8b0562558a0d2d907.tar.gz
ATRI-844bd56a5bed1293329299c8b0562558a0d2d907.tar.bz2
ATRI-844bd56a5bed1293329299c8b0562558a0d2d907.zip
🐛⚡️🔥 更新
修复: - `setu`、`saucenao`搜图时失败报错 更新: - 弃用`aiohttp`,改用`httpx` 删除: - 临时删除暂未完成的`console`
Diffstat (limited to 'ATRI/utils')
-rw-r--r--ATRI/utils/request.py57
1 files changed, 7 insertions, 50 deletions
diff --git a/ATRI/utils/request.py b/ATRI/utils/request.py
index 6ce3903..c208bbf 100644
--- a/ATRI/utils/request.py
+++ b/ATRI/utils/request.py
@@ -1,54 +1,11 @@
-from typing import Optional
-from aiohttp import ClientSession, ClientResponse, FormData
+import httpx
-class Response:
- def __init__(self, response: ClientResponse) -> None:
- self.raw_response = response
+async def get(url: str, **kwargs):
+ async with httpx.AsyncClient(proxies=proxy) as client:
+ return await client.get(url, **kwargs)
- @property
- def status(self) -> int:
- return self.raw_response.status
- @property
- def url(self):
- return self.raw_response.url
-
- @property
- def real_url(self):
- return self.raw_response.real_url
-
- @property
- def host(self):
- return self.raw_response.host
-
- @property
- def headers(self):
- return self.raw_response.headers
-
- @property
- def raw_headers(self):
- return self.raw_response.raw_headers
-
- @property
- def request_info(self):
- return self.raw_response.request_info
-
- @property
- async def read(self):
- return await self.raw_response.read()
-
- @property
- async def text(self):
- return await self.raw_response.text()
-
- async def json(self):
- return await self.raw_response.json()
-
-
-async def get(url, params: dict = None, **kwargs) -> Response:
- return Response(await ClientSession().get(url=url, params=params, **kwargs))
-
-
-async def post(url, data: Optional[FormData] = None, **kwargs) -> Response:
- return Response(await ClientSession().post(url=url, data=data, **kwargs))
+async def post(url: str, **kwargs):
+ async with httpx.AsyncClient(proxies=proxy) as client:
+ return await client.post(url, **kwargs)