V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
dawnzhu
V2EX  ›  问与答

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

  •  
  •   dawnzhu · 2020-07-16 11:00:01 +08:00 · 1808 次点击
    这是一个创建于 1384 天前的主题,其中的信息可能已经有所发展或是发生改变。
    # -*- 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)]

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2793 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 10:48 · PVG 18:48 · LAX 03:48 · JFK 06:48
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.