Closed
Description
Long story short
request proxy behavior is inconsistent within one session:
import asyncio
import aiohttp
class ProxyCrawler:
def __init__(self):
loop = asyncio.get_event_loop()
self.session = aiohttp.ClientSession(loop=loop)
async def req(self):
async with self.session.get('http://httpbin.org/ip') as resp:
text = await resp.text()
print('First request:')
print(text)
async with self.session.get('http://httpbin.org/ip', proxy='http://127.0.0.1:1087') as resp:
text = await resp.text()
print('Second request:')
print(text)
await self.session.close()
if __name__ == '__main__':
loop = asyncio.get_event_loop()
c = ProxyCrawler()
loop.run_until_complete(c.req())Expected behaviour
The first request goes directly, and the second request goes through the specified proxy.
Actual behaviour
Both requests go directly without proxy.
( But if you set the first request go through a proxy, the second request will go through the specified proxy correctly. )
Steps to reproduce
Run the code above ( replace the proxy with yours ).
Your environment
aiohttp: 3.2.0
Mac OS X