urllib3 using an ssh connection as proxy

456 Views Asked by At

I have an ssh connection as below in my local laptop:

ssh -f -N -D 3232 USER@IP

now in telepot which using from urllib3 i want to pass all connections to this ssh connection because Telegram servers has been banned in my office. I read this and do what it said. but when I use this:

proxy_url = 'http:localhost:3232

I get this error:

urllib3.exceptions.ProxyError: ('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f22968e5710>: Failed to establish a new connection: [Errno 111] Connection refused',))

How can i connect to this server?

2

There are 2 best solutions below

0
On BEST ANSWER

If you use older version of urllib3 you ,ust upgrade it using sudo pip install urllib3 --upgrade. Then you must install PySocks using sudo pip2 install PySocks. After these two steps you must change the code here to this:

proxy_url = 'socks5://localhost:PORT'

telepot.api._pools = { 
            'default': SOCKSProxyManager(proxy_url=proxy_url, num_pools=3, maxsize=10, retries=False, timeout=30),
            }

telepot.api._onetime_pool_spec = (SOCKSProxyManager, dict(proxy_url=proxy_url, num_pools=1, maxsize=1, retries=False, timeout=30))
0
On

In case you can't find SOCKSProxyManager, use the below import:

from urllib3.contrib.socks import SOCKSProxyManager