aiohttp 中使用代理

Python中…
算了不废话了,直接上代码

  • 安装包
pip install aiohttp aiohttp_socks
  • 使用
import asyncio
import aiohttp
import aiohttp_socks

async def main():
    proxies = "socks5://localhost:10808"
    conn = aiohttp_socks.ProxyConnector.from_url(proxies)
    async with aiohttp.ClientSession(connector=conn) as session:
        url = "https://ipapi.co/json"
        async with session.get(url) as response:
            print(response.status)
            print(await response.text())

asyncio.run(main())

一眼明了,不耽误大家时间~!

你可能感兴趣的:(python,开发语言)