From 6af3067a1293cca4c5c98f08bc1c956eeb8051bf Mon Sep 17 00:00:00 2001 From: eternnoir Date: Wed, 28 Jun 2017 17:44:07 +0800 Subject: [PATCH 1/2] Add proxy to readme. --- README.md | 11 +++++++++++ telebot/apihelper.py | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b056d0399..369e98f98 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ * [The listener mechanism](#the-listener-mechanism) * [Using web hooks](#using-web-hooks) * [Logging](#logging) + * [Proxy](#proxy) * [F.A.Q.](#faq) * [Bot 2.0](#bot-20) * [How can I distinguish a User and a GroupChat in message.chat?](#how-can-i-distinguish-a-user-and-a-groupchat-in-messagechat) @@ -492,6 +493,16 @@ logger = telebot.logger telebot.logger.setLevel(logging.DEBUG) # Outputs debug messages to console. ``` +### Proxy + +You can use proxy for request. `apihelper.proxy` object will use by call `requests` proxies argument. + +```python +from telebot import apihelper + +apihelper.proxy = {'http', 'http://10.10.1.10:3128'} +``` + ## F.A.Q. ### Bot 2.0 diff --git a/telebot/apihelper.py b/telebot/apihelper.py index 9276a924a..c2f1141d5 100644 --- a/telebot/apihelper.py +++ b/telebot/apihelper.py @@ -19,6 +19,7 @@ logger = telebot.logger req_session = requests.session() +proxy = None API_URL = "https://api.telegram.org/bot{0}/{1}" FILE_URL = "https://api.telegram.org/file/bot{0}/{1}" @@ -47,7 +48,7 @@ def _make_request(token, method_name, method='get', params=None, files=None, bas if 'timeout' in params: read_timeout = params['timeout'] + 10 if 'connect-timeout' in params: connect_timeout = params['connect-timeout'] + 10 result = req_session.request(method, request_url, params=params, files=files, - timeout=(connect_timeout, read_timeout)) + timeout=(connect_timeout, read_timeout), proxies=proxy) logger.debug("The server returned: '{0}'".format(result.text.encode('utf8'))) return _check_result(method_name, result)['result'] From 3e04df7080899c889bf05b411135e8c57ea40a43 Mon Sep 17 00:00:00 2001 From: FrankWang Date: Wed, 28 Jun 2017 18:01:07 +0800 Subject: [PATCH 2/2] Update README.md --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 369e98f98..48b6e1c94 100644 --- a/README.md +++ b/README.md @@ -503,6 +503,16 @@ from telebot import apihelper apihelper.proxy = {'http', 'http://10.10.1.10:3128'} ``` +If you want to use socket5 proxy you need install dependency `pip install requests[socks]`. + +```python +proxies = { + 'http': 'socks5://user:pass@host:port', + 'https': 'socks5://user:pass@host:port' +} +``` + + ## F.A.Q. ### Bot 2.0