Skip to content

Socks proxy error #1077

@maxgrechnev

Description

@maxgrechnev

Steps to reproduce

The code compares behaviour of two libs: urllib3 and python-telegram-bot:

TOKEN = '<your_api_token>'
SOCKS_URL = 'socks5://<your_sock5_proxy_host>:1080/'
SOCKS_USER = '<your_sock5_proxy_user>'
SOCKS_PASS = '<your_sock5_proxy_password>'

################## urllib3 ##################

import urllib3
urllib3.disable_warnings()
from urllib3.contrib.socks import SOCKSProxyManager

manager = SOCKSProxyManager(
	SOCKS_URL,
	username = SOCKS_USER,
	password = SOCKS_PASS,
)
response = manager.request('GET', 'https://api.telegram.org/bot' + TOKEN + '/getMe')
print response.data

############ python-telegram-bot ############

from telegram.utils.request import Request
from telegram import Bot

bot = Bot(
	TOKEN,
	request = Request(
		proxy_url = SOCKS_URL,
		urllib3_proxy_kwargs = {
				'username': SOCKS_USER,
				'password': SOCKS_PASS,
		},
	)
)
print str(bot.get_me().id)

Expected behaviour

I expect the same behaviour of both libraries: urllib3 and python-telegram-bot.

Actual behaviour

urllib3 works well, but python-telegram-bot raises telegram.error.NetworkError.

Configuration

Operating System:
Linux test 4.14.30-v7+ #1102 SMP Mon Mar 26 16:45:49 BST 2018 armv7l GNU/Linux
Raspbian GNU/Linux 9 (stretch)

Version of Python, python-telegram-bot & dependencies:
python-telegram-bot 10.0.2
certifi 2018.01.18
future 0.16.0
urllib3 1.22
PySocks 1.6.8
Python 2.7.13 (default, Nov 24 2017, 17:33:09) [GCC 6.3.0 20170516]

Logs

Output of the code:

{"ok":true,"result":{"id":584331883,"is_bot":true,"first_name":"Test","username":"TestSocksBot"}}
Traceback (most recent call last):
  File "/usr/lib/test/test.py", line 33, in <module>
	print str(bot.get_me().id)
  File "/usr/local/lib/python2.7/dist-packages/telegram/bot.py", line 60, in decorator
	result = func(self, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/telegram/bot.py", line 191, in get_me
	result = self._request.get(url, timeout=timeout)
  File "/usr/local/lib/python2.7/dist-packages/telegram/utils/request.py", line 245, in get
	result = self._request_wrapper('GET', url, **urlopen_kwargs)
  File "/usr/local/lib/python2.7/dist-packages/telegram/utils/request.py", line 201, in _request_wrapper
	raise NetworkError('urllib3 HTTPError {0}'.format(error))
telegram.error.NetworkError: urllib3 HTTPError SOCKSHTTPSConnectionPool(host='api.telegram.org', port=443): Max retries exceeded with url: /bot<your_api_token>/getMe (Caused by NewConnectionError('<telegram.vendor.ptb_urllib3.urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7624d7f0>: Failed to establish a new connection: 0x02: Connection not allowed by ruleset',))

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions