From 77d4221ed8b8021da4e0ad3e636fb0d8d34523d5 Mon Sep 17 00:00:00 2001 From: nibrag Date: Sun, 4 Jun 2017 18:57:25 +0300 Subject: [PATCH] Add proxy_from_env to ProxyClientRequest to read from environment --- README.rst | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 333ea0f..9ce7743 100644 --- a/README.rst +++ b/README.rst @@ -15,7 +15,7 @@ SOCKS proxy client for asyncio and aiohttp Dependencies ------------ python 3.5+ -aiohttp 2.0+ +aiohttp 2.1+ Features -------- @@ -185,3 +185,22 @@ aiohttp usage loop = asyncio.get_event_loop() loop.run_until_complete(load_github_main()) loop.close() + +Proxy from environment +^^^^^^^^^^^^^^^^^^^^^^ + +.. code-block:: python + + import os + from aiosocks.connector import ProxyConnector, ProxyClientRequest + + os.environ['socks4_proxy'] = 'socks4://127.0.0.1:333' + # or + os.environ['socks5_proxy'] = 'socks5://127.0.0.1:444' + + conn = ProxyConnector() + + with aiohttp.ClientSession(connector=conn, request_class=ProxyClientRequest) as session: + async with session.get('http://github.com/', proxy_from_env=True) as resp: + if resp.status == 200: + print(await resp.text())