From 573264b422b56b173f7269c1c017e8be66d776f4 Mon Sep 17 00:00:00 2001 From: Alex Root Junior Date: Sun, 22 Apr 2018 22:12:25 +0300 Subject: [PATCH 1/4] Upd requirements. --- dev_requirements.txt | 2 +- requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dev_requirements.txt b/dev_requirements.txt index a66ce75d..ba4f32bf 100644 --- a/dev_requirements.txt +++ b/dev_requirements.txt @@ -8,7 +8,7 @@ uvloop>=0.9.1 aioredis>=1.1.0 wheel>=0.31.0 rethinkdb>=2.3.0 -sphinx>=1.7.2 +sphinx>=1.7.3 sphinx-rtd-theme>=0.3.0 aresponses>=1.0.0 tox>=3.0.0 diff --git a/requirements.txt b/requirements.txt index 456d515a..9497f245 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ aiohttp>=3.1.3 Babel>=2.5.3 -certifi>=2018.01.18 +certifi>=2018.4.16 From c672faed0bd151961a61098c37b994f3f2a09750 Mon Sep 17 00:00:00 2001 From: Alex Root Junior Date: Sun, 22 Apr 2018 22:16:50 +0300 Subject: [PATCH 2/4] Upd proxy example. --- examples/proxy_and_emojize.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/proxy_and_emojize.py b/examples/proxy_and_emojize.py index 2b5f5d2d..dcc9406b 100644 --- a/examples/proxy_and_emojize.py +++ b/examples/proxy_and_emojize.py @@ -10,12 +10,13 @@ from aiogram.utils.markdown import bold, code, italic, text # Configure bot here API_TOKEN = 'BOT TOKEN HERE' -PROXY_URL = 'http://PROXY_URL' +PROXY_URL = 'http://PROXY_URL' # Or 'socks5://...' # If authentication is required in your proxy then uncomment next line and change login/password for it # PROXY_AUTH = aiohttp.BasicAuth(login='login', password='password') # And add `proxy_auth=PROXY_AUTH` argument in line 25, like this: # >>> bot = Bot(token=API_TOKEN, loop=loop, proxy=PROXY_URL, proxy_auth=PROXY_AUTH) +# Also you can use Socks5 proxy but you need manually install aiosocksy package. # Get my ip URL GET_IP_URL = 'http://bot.whatismyipaddress.com/' From a76d95fd71f329351a5dd2375a635db1635d9c75 Mon Sep 17 00:00:00 2001 From: Alex Root Junior Date: Sun, 22 Apr 2018 22:27:39 +0300 Subject: [PATCH 3/4] Change stage. --- aiogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aiogram/__init__.py b/aiogram/__init__.py index 6eff73fe..1e53b213 100644 --- a/aiogram/__init__.py +++ b/aiogram/__init__.py @@ -20,7 +20,7 @@ else: asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) -VERSION = Version(1, 3, 0, stage=Stage.DEV, build=0) +VERSION = Version(1, 3, 0, stage=Stage.FINAL, build=0) API_VERSION = Version(3, 6) __version__ = VERSION.version From 2808da3807846b777a6af131a5782daffb48e046 Mon Sep 17 00:00:00 2001 From: Arslan Sakhapov Date: Tue, 24 Apr 2018 19:26:53 +0500 Subject: [PATCH 4/4] Add example of using a socks proxy --- examples/socks_proxy.py | 49 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 examples/socks_proxy.py diff --git a/examples/socks_proxy.py b/examples/socks_proxy.py new file mode 100644 index 00000000..f048f7d9 --- /dev/null +++ b/examples/socks_proxy.py @@ -0,0 +1,49 @@ +import asyncio +import logging + +from aiohttp import ClientSession +from aiosocksy.connector import ProxyConnector, ProxyClientRequest + +from aiogram import Bot, types +from aiogram.dispatcher import Dispatcher +from aiogram.types import ParseMode +from aiogram.utils.executor import start_polling +from aiogram.utils.markdown import bold, code, italic, text + +# Configure bot here +API_TOKEN = '' +PROXY_URL = 'socks5://...' +# If authentication is required in your proxy then uncomment next line and change login/password for it +# PROXY_AUTH = aiosocksy.Socks5Auth(login='login', password='password') +# And add `proxy_auth=PROXY_AUTH` argument in line 25, like this: +# >>> bot = Bot(token=API_TOKEN, loop=loop, proxy=PROXY_URL, proxy_auth=PROXY_AUTH) + +# Get my ip URL +GET_IP_URL = 'http://bot.whatismyipaddress.com/' + +logging.basicConfig(level=logging.INFO) + +loop = asyncio.get_event_loop() +bot = Bot(token=API_TOKEN, loop=loop, proxy=PROXY_URL, proxy_auth=PROXY_AUTH) +dp = Dispatcher(bot) + + +@dp.message_handler(commands=['start']) +async def cmd_start(message: types.Message): + content = [] + + # Make request (without proxy) + async with ClientSession() as session: + async with session.get(GET_IP_URL) as response: + content.append(text('🌎', bold('IP:'), code(await response.text()))) + + # Make request through proxy + async with ClientSession(connector=ProxyConnector(), request_class=ProxyClientRequest) as session: + async with session.get(GET_IP_URL, proxy=bot.proxy, proxy_auth=bot.proxy_auth) as response: + content.append(text('🔐', bold('IP:'), code(await response.text()), italic('via proxy'))) + + await bot.send_message(message.chat.id, text(*content, sep='\n'), parse_mode=ParseMode.MARKDOWN) + + +if __name__ == '__main__': + start_polling(dp, loop=loop, skip_updates=True)