async def SendHttpReq(url, method, params=None, data=None,
headers=None,verify=None, cert=None, json_data=None):
async with httpx.AsyncClient() as client:
if (method == "GET"):
response = await client.get(url)
return response
比如我外部函数想调用这个 SendHttpReq,取到 response 。这个不能直接像函数一样 resp = SendHttpReq()。
1
Vegetable 2021 年 1 月 25 日
外部也需要 resp =await SendHttpReq()
|
2
towry 2021 年 1 月 25 日
```py
import asyncio resp = asyncio.ensure_future(SendHttpReq('url', 'GET')) ``` |
3
cocowind 2021 年 1 月 26 日
0.0 题外话,httpx,aiohttp 这种异步 http 库都会有套接字溢出的问题.
请见 requests 文档介绍: Requests 唯一的一个非转基因的 Python HTTP 库,人类可以安全享用。 警告:非专业使用其他 HTTP 库会导致危险的副作用,包括:安全缺陷症、冗余代码症、重新发明轮子症、啃文档症、抑郁、头疼、甚至死亡。 |
4
julyclyde 2021 年 1 月 26 日
上面 await 和 ensure_future 的区别在哪方面呢
|