Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

When I want to connect to telegram bot using Tor that returns error blow

requests.exceptions.ConnectTimeout: HTTPSConnectionPool(host='api.telegram.org', port=443): Max retries exceeded with url: /bot/getUpdates?offset=1&timeout=20 (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x7f28923f4a30>, 'Connection to api.telegram.org timed out. (connect timeout=20)'))

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
592 views
Welcome To Ask or Share your Answers For Others

1 Answer

first install tor using sudo apt install tor then run commeds blow

sudo apt install privoxy torsocks

nano /etc/privoxy/config

then uncommnet line that contains forward-socks5t / 127.0.0.1:9050 .

now

sudo systemctl enable privoxy.service
sudo systemctl start privoxy.service

now make sure that in /etc/tor/torsocks.conf file commends blow are uncommnted

TorAddress 127.0.0.1
TorPort 9050

next add codes blow in your bot source code

from telebot import apihelper

apihelper.proxy = {'https': 'socks5h://127.0.0.1:9050',
#    'http':'http://127.0.0.1:8118',
#    'https':'https://127.0.0.1:8118'
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...