Skip to content

Commit 514880f

Browse files
committed
Merge remote-tracking branch 'origin/proxySupport'
2 parents f97bb2f + 3e04df7 commit 514880f

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

‎README.md‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
* [The listener mechanism](#the-listener-mechanism)
2626
* [Using web hooks](#using-web-hooks)
2727
* [Logging](#logging)
28+
* [Proxy](#proxy)
2829
* [F.A.Q.](#faq)
2930
* [Bot 2.0](#bot-20)
3031
* [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,26 @@ logger = telebot.logger
492493
telebot.logger.setLevel(logging.DEBUG) # Outputs debug messages to console.
493494
```
494495

496+
### Proxy
497+
498+
You can use proxy for request. `apihelper.proxy` object will use by call `requests` proxies argument.
499+
500+
```python
501+
from telebot import apihelper
502+
503+
apihelper.proxy = {'http', 'http://10.10.1.10:3128'}
504+
```
505+
506+
If you want to use socket5 proxy you need install dependency `pip install requests[socks]`.
507+
508+
```python
509+
proxies = {
510+
'http': 'socks5://user:pass@host:port',
511+
'https': 'socks5://user:pass@host:port'
512+
}
513+
```
514+
515+
495516
## F.A.Q.
496517

497518
### Bot 2.0

‎telebot/apihelper.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
logger = telebot.logger
2121
req_session = requests.session()
22+
proxy = None
2223

2324
API_URL = "https://api.telegram.org/bot{0}/{1}"
2425
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
4748
if 'timeout' in params: read_timeout = params['timeout'] + 10
4849
if 'connect-timeout' in params: connect_timeout = params['connect-timeout'] + 10
4950
result = req_session.request(method, request_url, params=params, files=files,
50-
timeout=(connect_timeout, read_timeout))
51+
timeout=(connect_timeout, read_timeout), proxies=proxy)
5152
logger.debug("The server returned: '{0}'".format(result.text.encode('utf8')))
5253
return _check_result(method_name, result)['result']
5354

0 commit comments

Comments
 (0)