Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/proxySupport'
Browse files Browse the repository at this point in the history
  • Loading branch information
eternnoir committed Jul 1, 2017
2 parents f97bb2f + 3e04df7 commit 514880f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -492,6 +493,26 @@ 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'}
```

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
Expand Down
3 changes: 2 additions & 1 deletion telebot/apihelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -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']

Expand Down

0 comments on commit 514880f

Please sign in to comment.