Gozargah / Marzban

Unified GUI Censorship Resistant Solution Powered by Xray
https://t.me/gozargah_marzban
GNU Affero General Public License v3.0
3.27k stars 459 forks source link

Socks5 as TELEGRAM_PROXY in .env file #773

Closed hakramzade closed 6 months ago

hakramzade commented 7 months ago

In the .env file there is a variable called "TELEGRAM_PROXY" which is being used as proxy server to connect to TelegramAPI servers using python telebot library using socks5 as proxy in python telebot is possible and supported IF "pysocks" and "requests[socks]" is available in python libraries.

To Reproduce the issue:

  1. simply use any socks5 proxy address as TELEGRAM_PROXY in .env file. (I always alternatively check the proxy response with this command, you can do it too: curl -x <socks5Proxy> ip.sb socks5Proxy format: socks5://userproxy:password@proxy_address:port this must return the proxy public ipv4)

  2. restart the marzban and you constantly get this error which can be solved if you install "pysocks" and "requests[socks]" on the docker container. LOG:

    marzban-1  | Traceback (most recent call last):
    marzban-1  |   File "/usr/local/lib/python3.10/site-packages/telebot/__init__.py", line 955, in infinity_polling
    marzban-1  |     self.polling(non_stop=True, timeout=timeout, long_polling_timeout=long_polling_timeout,
    marzban-1  |   File "/usr/local/lib/python3.10/site-packages/telebot/__init__.py", line 1040, in polling
    marzban-1  |     logger.info('Starting your bot with username: [@%s]', self.user.username)
    marzban-1  |   File "/usr/local/lib/python3.10/site-packages/telebot/__init__.py", line 273, in user
    marzban-1  |     self._user = self.get_me()
    marzban-1  |   File "/usr/local/lib/python3.10/site-packages/telebot/__init__.py", line 1236, in get_me
    marzban-1  |     result = apihelper.get_me(self.token)
    marzban-1  |   File "/usr/local/lib/python3.10/site-packages/telebot/apihelper.py", line 196, in get_me
    marzban-1  |     return _make_request(token, method_url)
    marzban-1  |   File "/usr/local/lib/python3.10/site-packages/telebot/apihelper.py", line 156, in _make_request
    marzban-1  |     result = _get_req_session().request(
    marzban-1  |   File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line 587, in request
    marzban-1  |     resp = self.send(prep, **send_kwargs)
    marzban-1  |   File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line 701, in send
    marzban-1  |     r = adapter.send(request, **kwargs)
    marzban-1  |   File "/usr/local/lib/python3.10/site-packages/requests/adapters.py", line 456, in send
    marzban-1  |     conn = self.get_connection(request.url, proxies)
    marzban-1  |   File "/usr/local/lib/python3.10/site-packages/requests/adapters.py", line 352, in get_connection
    marzban-1  |     proxy_manager = self.proxy_manager_for(proxy)
    marzban-1  |   File "/usr/local/lib/python3.10/site-packages/requests/adapters.py", line 217, in proxy_manager_for
    marzban-1  |     manager = self.proxy_manager[proxy] = SOCKSProxyManager(
    marzban-1  |   File "/usr/local/lib/python3.10/site-packages/requests/adapters.py", line 62, in SOCKSProxyManager
    marzban-1  |     raise InvalidSchema("Missing dependencies for SOCKS support.")
    marzban-1  | requests.exceptions.InvalidSchema: Missing dependencies for SOCKS support.
    marzban-1  | "
    • OS: ubuntu 20

Additional context: If you have trouble finding a socks5 proxy, you can use ssh connection to one of your servers as a socks proxy server. Here is how you can do:

  1. use "screen" to keep the proxy command alive: screen -S proxy
  2. run proxy command (and press return after successfully connecting to your server to activate it): ssh -N -D <custom_port> user@server
  3. detach from the screen: Press CTRL+A+D
  4. test your proxy: use this command to check if your proxy is running well or not. this should return the public IP of your ssh server. curl -x localhost:<custom_port> ip.sb
M03ED commented 7 months ago

i think it only support http proxy not socks5

hakramzade commented 7 months ago

i think it only support http proxy not socks5

It do supports http but they updated the library and now It also supports socks5 Check this out: https://github.com/eternnoir/pyTelegramBotAPI?tab=readme-ov-file#proxy

P.S.: I used a tool called pproxy to convert my local socks proxy to local http proxy. I don't know if it is useful to anyone but the problem is solved for now as I'm using http instead socks

pip3 install pproxy
pproxy -l http://0.0.0.0:<unused_port> -r socks5://<userproxy:password@proxy_address:port>

now you can use http proxy as TELEGRAM_PROXY

M03ED commented 7 months ago

It do supports http but they updated the library and now It also supports socks5 Check this out: https://github.com/eternnoir/pyTelegramBotAPI?tab=readme-ov-file#proxy

marzban is using 4.9.0 version and latest version is 4.15.2 if you are interest you can sync marzban with last version and make a pull request

hakramzade commented 7 months ago

It do supports http but they updated the library and now It also supports socks5 Check this out: https://github.com/eternnoir/pyTelegramBotAPI?tab=readme-ov-file#proxy

marzban is using 4.9.0 version and latest version is 4.15.2 if you are interest you can sync marzban with last version and make a pull request

I'm a newbie in github, cannot do that. it would be great if you guys make it for next marzban update. Thanks for you great work and effort! ⭐️