通过Python连接电报机器人时出现问题

2024-09-30 02:17:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图根据this tutorial使用Python建立一个电报机器人。我用Python编写的最后一个脚本是

import telebot

bot_name='gfjhsbot'
bot_api='1529995319:AAGb34vl-FkYRESLMZuIsTdrlLlP7mPHEyw'

bot=telebot.TeleBot(bot_api)

@bot.message_handler(commands=['greet'])
def greet_func(message):
    bot.reply_to(message,'The first telegram bot is cool!')

bot.polling()

正常情况下,它应该可以工作,但不幸的是,电报被过滤了,我通过代理连接到我自己的帐户,如我的电报windows环境中的下图所示: enter image description here

我的一个代理样本是

https://t.me/proxy?server=3.66.228.40&port=443&secret=dd7aaaaaaaaaaaaabbbbbbbbbbbbbbcd61

因此,上面的Python脚本不起作用(在bot中运行脚本并将/greet作为命令写入时,我没有得到我期望的'The first telegram bot is cool!'响应),大约5秒后返回以下错误:

SSLError: HTTPSConnectionPool(host='api.telegram.org', port=443):
Max retries exceeded with url: /bot1529995319:AAGb34vl-FkYRESLMZuIsTdrlLlP7mPHEyw/getUpdates?offset=1&timeout=20
(Caused by SSLError(SSLError("bad handshake: SysCallError(10054, 'WSAECONNRESET')")))

问题:

How can I connect to telegram bot through proxy using a Python line of code?

提前谢谢


Tags: theto脚本apimessageisbot电报

热门问题