aiohttp 请求如何使用代理,大哥们帮帮小弟

2020-07-16 11:00:01 +08:00
 dawnzhu
# -*- coding: utf-8 -*-
import asyncio
import aiohttp
import requests

'''requests'''
res = requests.get('https://icanhazip.com', proxies={'http': 'http://36.249.119.38:9999'})
print(res.text)
print("async......")


async def func1():  # async
    async with aiohttp.ClientSession() as session:
        async with session.get("https://icanhazip.com", proxy='http://36.249.119.38:9999') as r:
            print('---------------------------------')
            print(await r.text())


asyncio.run(func1())

请求结果

113.118.175.175

async......

.....aiohttp.client_exceptions.ClientProxyConnectionError: Cannot connect to host 36.249.119.38:9999 ssl:default [Connect call failed ('36.249.119.38', 9999)]

1831 次点击
所在节点    问与答
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/690505

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX