Skip to content
This repository has been archived by the owner on Jun 2, 2019. It is now read-only.

socks proxy support #386

Closed
wants to merge 1 commit into from
Closed

socks proxy support #386

wants to merge 1 commit into from

Conversation

botfarmer
Copy link

@botfarmer botfarmer commented Apr 17, 2018

To connect through socks proxies
telepot.api.set_proxy('socks5://mytor.proxy.net:9050')
to send DNS requests to proxy
telepot.api.set_proxy('socks5h://mytor.proxy.net:9050')

To connect through socks proxies
telepot.api.set_proxy('socks5://mytor.proxy.net:9050')
# to send DNS requests to proxy
telepot.api.set_proxy('socks5h://mytor.proxy.net:9050')
@botfarmer botfarmer closed this Apr 17, 2018
@botfarmer botfarmer deleted the patch-1 branch April 17, 2018 18:13
@botfarmer botfarmer restored the patch-1 branch April 17, 2018 18:14
@b0g3r
Copy link

b0g3r commented Apr 22, 2018

@Oldun Why closed?

@botfarmer
Copy link
Author

botfarmer commented Apr 24, 2018

Found the issue #355 and nickoala comment

In conclusion, SOCKS proxy will not become part of telepot.

For now I'm using monkeypatch (modifying protected members of a module)

def set_telepot_socks_proxy(url, username=None, password=None):
    from urllib3.contrib.socks import SOCKSProxyManager
    from telepot.api import _default_pool_params, _onetime_pool_params
    telepot.api._onetime_pool_spec = (SOCKSProxyManager, dict(proxy_url=url, username=username, password=password, **_onetime_pool_params))
    telepot.api._pools['default'] = SOCKSProxyManager(url, username=username, password=password, **_default_pool_params)

it requires PySocks package

pip install PySocks
or
pip install urllib3[socks]

@nickoala
Copy link
Owner

Sorry for the slow reply. I can understand the desire for sock proxy support, especially that Telegram gets banned by some more governments these days. Personally, however, I am just not ready to commit much more time to telepot these days, and hate for it to depend on more libraries than are strictly necessary.

Thanks to @Oldun for providing the work-around. That would be a good reference for anyone who wants to do it.

@das7pad das7pad mentioned this pull request May 21, 2018
@ivanvoloshin
Copy link

ivanvoloshin commented Dec 15, 2018

@Oldun I tried to use your workaround, but unfortunately it doesn't work.

I entered username and password instead of None, and then called a function with url parameter like this:
set_telepot_socks_proxy("socks5://ip:port")

I get Connection refused error when I run my script. May be I've made any mistake in url parameter?

@botfarmer
Copy link
Author

You should use socks5h if api.telegram.org is blocked

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants