【问题标题】:Telegram bot failed to establish a new connection [WinError 10061]Telegram 机器人无法建立新连接 [WinError 10061]
【发布时间】:2021-03-13 18:37:05
【问题描述】:

我尝试编写一个简单的 Telegram 机器人,但 Telegram 在我的国家受到审查 所以我使用代理来连接电报

这是错误信息

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "F:\VS Pj\Telegram Bot\venv\lib\site-packages\telegram\utils\request.py", line 252, in _request_wrapper 
    resp = self._con_pool.request(*args, **kwargs)
  File "F:\VS Pj\Telegram Bot\venv\lib\site-packages\telegram\vendor\ptb_urllib3\urllib3\request.py", line 68, 
in request
    return self.request_encode_body(method, url, fields=fields,
  File "F:\VS Pj\Telegram Bot\venv\lib\site-packages\telegram\vendor\ptb_urllib3\urllib3\request.py", line 148, in request_encode_body
    return self.urlopen(method, url, **extra_kw)
  File "F:\VS Pj\Telegram Bot\venv\lib\site-packages\telegram\vendor\ptb_urllib3\urllib3\poolmanager.py", line 
244, in urlopen
    response = conn.urlopen(method, u.request_uri, **kw)
  File "F:\VS Pj\Telegram Bot\venv\lib\site-packages\telegram\vendor\ptb_urllib3\urllib3\connectionpool.py", line 691, in urlopen
    return self.urlopen(method, url, body, headers, retries,
  File "F:\VS Pj\Telegram Bot\venv\lib\site-packages\telegram\vendor\ptb_urllib3\urllib3\connectionpool.py", line 691, in urlopen
    return self.urlopen(method, url, body, headers, retries,
  File "F:\VS Pj\Telegram Bot\venv\lib\site-packages\telegram\vendor\ptb_urllib3\urllib3\connectionpool.py", line 691, in urlopen
    return self.urlopen(method, url, body, headers, retries,
  File "F:\VS Pj\Telegram Bot\venv\lib\site-packages\telegram\vendor\ptb_urllib3\urllib3\connectionpool.py", line 665, in urlopen
    retries = retries.increment(method, url, error=e, _pool=self,
  File "F:\VS Pj\Telegram Bot\venv\lib\site-packages\telegram\vendor\ptb_urllib3\urllib3\util\retry.py", line 376, in increment

raise NetworkError(f'urllib3 HTTPError {error}') from error

telegram.error.NetworkError: urllib3 HTTPError HTTPSConnectionPool(host='api.telegram.org', 
port=443): Max retries exceeded with url: /bot...token.../getMe (Caused by 
NewConnectionError('<telegram.vendor.ptb_urllib3.urllib3.connection.VerifiedHTTPSConnection 
object at 0x000001917CBD7760>: Failed to establish a new connection: [WinError 10061] No 
connection could be made because the target machine actively refused it'))

这是我的代码:

from telegram.ext import Updater
from telegram.ext import CommandHandler

updater = Updater("...token...")

def start(bot,update):
    chat_id = update.message.chat_id

    bot.sendMessage(chat_id=chat_id,text='connected')

start_command = CommandHandler('start',start)

updater.dispatcher.add_handler(start_command)

updater.start_polling()
updater.idle()

我应该怎么做才能得到结果?

【问题讨论】:

  • “无法建立连接,因为目标机器主动拒绝了它”——对我来说似乎很清楚。无论如何,首先搜索该错误。然后,在你的问题中包含完整的回溯,这样人们就有机会看到是哪一行导致了它。另请注意,任何其他行(甚至未执行)都不是minimal reproducible example 的一部分。
  • 感谢您的评论@UlrichEckhardt
  • 我也有同样的问题?你能解决吗?

标签: python telegram-bot python-telegram-bot telegram-api


【解决方案1】:

使用过滤器断路器,因为 Telegram 在某些国家/地区是过滤器。 另外,不要使用 psiphon。

【讨论】:

    猜你喜欢
    • 2022-01-06
    • 1970-01-01
    • 2018-12-01
    • 2020-07-07
    • 2021-01-04
    • 1970-01-01
    • 2021-12-22
    • 1970-01-01
    相关资源
    最近更新 更多