Telegram tor local proxy port 9050

Hi!
ubuntu server 16.04, local tor proxy - port 9050.

  1. send message to telegram bot

curl --socks5-hostname localhost:9050 curl -s -X POST https://api.telegram.org/botXXX633034:AAHSXVi3xaBzysrhWe3Afl-XV4hNE8m0tuk/sendMessage -d chat_id=763244536 -d

  • works
  1. Home assistant - sending through a local proxy does not work
    configuration.yaml
    telegram_bot:
  • platform: polling
    api_key: !secret telegram_bot_api_key
    proxy_url: !secret telegram_bot_proxy_url
    proxy_params:
    username: !secret telegram_bot_proxy_username
    password: !secret telegram_bot_proxy_password
    allowed_chat_ids:
    • !secret telegram_bot_allowed_chat_id1
    • !secret telegram_bot_allowed_chat_id2

secrets.yaml
telegram_bot_api_key: XXXX33034:AAHSXVi3xaBzysrhWe3Afl-XV4hNE8m0tuk
telegram_bot_proxy_url: socks5h://127.0.0.1:9050
telegram_bot_proxy_username:
telegram_bot_proxy_password:
telegram_bot_allowed_chat_id1: 763244537
telegram_bot_allowed_chat_id2: 763244536

notify.yaml

  • name: telegram666
    platform: telegram
    chat_id: !secret telegram_bot_allowed_chat_id2

2.2 - error

Error setting up platform polling
Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.6/site-packages/telegram/utils/request.py”, line 125, in init
from telegram.vendor.ptb_urllib3.urllib3.contrib.socks import SOCKSProxyManager
File “/srv/homeassistant/lib/python3.6/site-packages/telegram/vendor/ptb_urllib3/urllib3/contrib/socks.py”, line 27, in
import socks
ModuleNotFoundError: No module named ‘socks’

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/telegram_bot/init.py”, line 251, in async_setup
platform.async_setup_platform(hass, p_config)
File “/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/telegram_bot/polling.py”, line 15, in async_setup_platform
bot = initialize_bot(config)
File “/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/telegram_bot/init.py”, line 334, in initialize_bot
urllib3_proxy_kwargs=proxy_params)
File “/srv/homeassistant/lib/python3.6/site-packages/telegram/utils/request.py”, line 127, in init
raise RuntimeError(‘PySocks is missing’)
RuntimeError: PySocks is missing

  1. how to make work through a local proxy?
  2. sorry for bad English

Try installing PySocks first. Something like this MIGHT work, depending on how you installed home assistant:

pip3 install PySocks

Thanks for the answer!
Installed PySocks, error same

You didn’t install it in the right place. It looks like you’re using virtualenv for HASS, and you probably didn’t install it in the virtual environment. You should try:

First - Change to the user that is running home-assistant using su/sudo

cd /srv/homeassistant
./bin/activate
./bin/pip3 install PySocks

cd /srv/homeassistant
source bin/activate
sudo ./bin/pip3 install PySocks

All Ok!!!
Спасибо тебе добрый человек!

1 Like