requests.exceptions.ConnectTimeout: HTTPSConnectionPool(host='api.telegram.org', port=443): # python 电报机器人使用 pytelegrambotapi 和 Tor

尼玛

当我想使用 Tor 连接到电报机器人时返回错误打击

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对象在 0x7f28923f4a30>,'连接到 api.telegram.org 超时。(连接超时 = 20)'))

尼玛

首先使用安装torsudo apt install tor然后运行commeds blow

sudo apt install privoxy torsocks

nano /etc/privoxy/config

然后 uncommnet 行包含 forward-socks5t / 127.0.0.1:9050 .

现在

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

现在确保在/etc/tor/torsocks.conf文件中推荐打击是 uncommnted

TorAddress 127.0.0.1
TorPort 9050

接下来在你的机器人源代码中添加代码

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'
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章