gpt4 book ai didi

python - 无法连接到主机 api.telegram.org :443 ssl:default

转载 作者:行者123 更新时间:2023-12-04 19:24:37 28 4
gpt4 key购买 nike

我正在 aiogram 框架上编写一个 Telegram Bot 。当我运行它时一切都很好,但今天我收到错误,Cannot connect to host 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]

最佳答案

您的基本网址应为 https://api.telegram.org/ , 话虽这么说,看到 ConnectionError 是很常见的和 ReadTimeout在投票期间。
但是,查看错误 socket.gaierror: [Errno -3] Temporary failure in name resolution获取主机的地址信息时出现问题。我会先排除任何连接问题,然后检查您的 /etc/hosts文件以查看是否有任何错误配置。
如果两者都不起作用,请尝试直接轮询 API 以查看问题是否仍然存在。
仅供引用:这是我在没有任何框架的情况下直接轮询 API 并且从未遇到问题的方式。
https://github.com/thevickypedia/Jarvis/blob/master/modules/telegram/bot.py

关于python - 无法连接到主机 api.telegram.org :443 ssl:default,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72303917/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com