dawnzhu
V2EX  ›  问与答

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

  •  
  •   dawnzhu · Jul 16, 2020 · 2626 views
    This topic created in 2131 days ago, the information mentioned may be changed or developed.
    # -*- 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)]

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1056 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 18:12 · PVG 02:12 · LAX 11:12 · JFK 14:12
    ♥ Do have faith in what you're doing.