无法连接到主机api.telegram.org:443 SSL:默认值

发布于 2025-01-30 09:56:01 字数 4813 浏览 2 评论 0 原文

我正在在AIOGRAM框架上写电报机器人。当我运行它时,一切都很好,但是今天我遇到了错误,无法连接到主机api.telegram.org:443 ssl:default 我不知道有什么问题。
我正在使用ubuntu 20.04.2 lts
这是完整的错误

Traceback (most recent call last):
  File "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiohttp/connector.py", line 1154, in _create_direct_connection
    hosts = await asyncio.shield(host_resolved)
  File "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiohttp/connector.py", line 880, in _resolve_host
    addrs = await self._resolver.resolve(host, port, family=self._family)
  File "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiohttp/resolver.py", line 33, in resolve
    infos = await self._loop.getaddrinfo(
  File "/usr/lib/python3.8/asyncio/base_events.py", line 825, in getaddrinfo
    return await self.run_in_executor(
  File "/usr/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/lib/python3.8/socket.py", line 918, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -3] Temporary failure in name resolution

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiogram/bot/api.py", line 139, in make_request
    async with session.post(url, data=req, **kwargs) as response:
  File "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiohttp/client.py", line 1138, in __aenter__
    self._resp = await self._coro
  File "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiohttp/client.py", line 535, in _request
    conn = await self._connector.connect(
  File "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiohttp/connector.py", line 542, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiohttp/connector.py", line 907, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
  File "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiohttp/connector.py", line 1166, in _create_direct_connection
    raise ClientConnectorError(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host api.telegram.org:443 ssl:default [Temporary failure in name resolution]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "app.py", line 18, in <module>
    executor.start_polling(dp, on_startup=on_startup)
  File "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiogram/utils/executor.py", line 45, in start_polling
    executor.start_polling(
  File "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiogram/utils/executor.py", line 320, in start_polling
    loop.run_until_complete(self._startup_polling())
  File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiogram/utils/executor.py", line 372, in _startup_polling
    await self._welcome()
  File "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiogram/utils/executor.py", line 361, in _welcome
    user = await self.dispatcher.bot.me
  File "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiogram/bot/bot.py", line 30, in me
    setattr(self, '_me', await self.get_me())
  File "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiogram/bot/bot.py", line 228, in get_me
    result = await self.request(api.Methods.GET_ME, payload)
  File "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiogram/bot/base.py", line 231, in request
    return await api.make_request(await self.get_session(), self.server, self.__token, method, data, files,
  File "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiogram/bot/api.py", line 142, in make_request
    raise exceptions.NetworkError(f"aiohttp client throws an error: {e.__class__.__name__}: {e}")
aiogram.utils.exceptions.NetworkError: Aiohttp client throws an error: ClientConnectorError: Cannot connect to host api.telegram.org:443 ssl:default [Temporary failure in name resolution]

I am writing a telegram bot on the aiogram framework. Everything was good when I run it, but today I am getting error,Cannot connect to host api.telegram.org:443 ssl:default I do not know what's problem.
I am using Ubuntu 20.04.2 LTS
Here is the full error

Traceback (most recent call last):
  File "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiohttp/connector.py", line 1154, in _create_direct_connection
    hosts = await asyncio.shield(host_resolved)
  File "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiohttp/connector.py", line 880, in _resolve_host
    addrs = await self._resolver.resolve(host, port, family=self._family)
  File "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiohttp/resolver.py", line 33, in resolve
    infos = await self._loop.getaddrinfo(
  File "/usr/lib/python3.8/asyncio/base_events.py", line 825, in getaddrinfo
    return await self.run_in_executor(
  File "/usr/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/lib/python3.8/socket.py", line 918, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -3] Temporary failure in name resolution

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiogram/bot/api.py", line 139, in make_request
    async with session.post(url, data=req, **kwargs) as response:
  File "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiohttp/client.py", line 1138, in __aenter__
    self._resp = await self._coro
  File "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiohttp/client.py", line 535, in _request
    conn = await self._connector.connect(
  File "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiohttp/connector.py", line 542, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiohttp/connector.py", line 907, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
  File "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiohttp/connector.py", line 1166, in _create_direct_connection
    raise ClientConnectorError(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host api.telegram.org:443 ssl:default [Temporary failure in name resolution]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "app.py", line 18, in <module>
    executor.start_polling(dp, on_startup=on_startup)
  File "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiogram/utils/executor.py", line 45, in start_polling
    executor.start_polling(
  File "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiogram/utils/executor.py", line 320, in start_polling
    loop.run_until_complete(self._startup_polling())
  File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiogram/utils/executor.py", line 372, in _startup_polling
    await self._welcome()
  File "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiogram/utils/executor.py", line 361, in _welcome
    user = await self.dispatcher.bot.me
  File "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiogram/bot/bot.py", line 30, in me
    setattr(self, '_me', await self.get_me())
  File "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiogram/bot/bot.py", line 228, in get_me
    result = await self.request(api.Methods.GET_ME, payload)
  File "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiogram/bot/base.py", line 231, in request
    return await api.make_request(await self.get_session(), self.server, self.__token, method, data, files,
  File "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiogram/bot/api.py", line 142, in make_request
    raise exceptions.NetworkError(f"aiohttp client throws an error: {e.__class__.__name__}: {e}")
aiogram.utils.exceptions.NetworkError: Aiohttp client throws an error: ClientConnectorError: Cannot connect to host api.telegram.org:443 ssl:default [Temporary failure in name resolution]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

小矜持 2025-02-06 09:56:01

我认为您正在pythonanywhere上运行Python Telegram bot脚本。如果这是真的,请确保您在bot实例中集成了代理设置:

bot = Bot(token='YOUR API TOKEN GOES HERE', proxy='http://proxy.server:3128')

如果已经设置了该设置,并且您仍然会从Pythonanywhere中获得与TLS-In-In-TLS相关的错误:

  1. 菜单选项上的Tap Consoles。
  2. 关闭脚本正在运行的控制台。
  3. 再次运行脚本。

I presume you are running your Python telegram bot script on PythonAnywhere. If this is true, ensure you have the proxy setup integrated in the bot instance:

bot = Bot(token='YOUR API TOKEN GOES HERE', proxy='http://proxy.server:3128')

If that has been setup and you still get the TLS-in-TLS-related error from PythonAnywhere:

  1. Tap consoles on the Menu option.
  2. Close the console in which your script is running.
  3. Run the script again.
陌路黄昏 2025-02-06 09:56:01

您的基本URL应该是 https://api.telegram.org/ ,也就是说,在此期间看到 connection> connection> connection> connection>轮询。

但是,查看错误 socket.gaierror:[errno -3]名称分辨率的临时故障在获取主机的地址信息时存在问题。我将从排除任何连接问题开始,然后检查您的/etc/hosts 文件,以查看是否有任何构造。

如果两者都没有起作用,请尝试直接对API进行轮询,以查看问题是否仍然存在。

通常,设置网络钩比长期投票要好得多。
它需要一些设置,需要API和像Ngrok这样的反向代理,但是一旦启动并运行,与长时间的投票相比,它是一种非常麻烦而优雅的解决方案。我创建了一个用于Telegram Webhooks的POC,如果您想从长期的投票转换为Webhooks,这可能会有所帮助。

概念证明

python

java

Your base url should be https://api.telegram.org/, with that being said it is common to see ConnectionError and ReadTimeout during polling.

But, looking at the error socket.gaierror: [Errno -3] Temporary failure in name resolution there is an issue in getting the address info for the host. I'd start with ruling out any connection issues and then check your /etc/hosts file to see if there are any misconfigurations.

If neither works, try polling the API directly to see if the problem still exists.

In general, setting up webhooks are much better than long polling.
It takes a bit of a setup, requires an API and a reverse proxy like ngrok, but once it is up and running, it is a very hassle free and elegant solution compared to long polling. I created a POC for telegram webhooks, which might be of help if you're looking to switch from long polling to webhooks.

Proof of concept

Python: https://github.com/thevickypedia/telegram-webhook

Java: https://github.com/thevickypedia/telegram-webhook-spring

陌伤浅笑 2025-02-06 09:56:01

在WSL2上运行时,我遇到了错误。我通过编辑此文件修复了它:

/etc/resolv.conf

并添加两个名称服务器:

nameserver 8.8.8.8
nameserver 8.8.4.4

I encountered the error while running on WSL2. I fixed it by editing this file:

/etc/resolv.conf

And adding two nameservers:

nameserver 8.8.8.8
nameserver 8.8.4.4
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文