电报不再接受通配符证书。Pythonywhere中获取错误

2024-09-28 22:04:58 发布

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

在pythonywhere上部署bot时,我无法向bot发送消息。由于telegram不再支持通配符证书(如官方Pythonywhere博客link to the blog post中所述),无法将错误发送到服务器。如果有人知道此问题的原因,请帮助我解决

  raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.telegram.org', port=443): Max retries exceeded with url: /bottokenvalue/sendMessage (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f094debf050>: Failed to establish a new connection: [Errno 101] Network is unreachable'))
2020-01-17 21:58:04,377: Retrying (Retry(total=2, connect=None, read=None, redirect=0, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f094da4c610>: Failed to establish a new connection: [Errno 101] Network is unreachable')': /bottoken/sendMessage
2020-01-17 21:58:05,377: Retrying (Retry(total=1, connect=None, read=None, redirect=0, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f094da4c4d0>: Failed to establish a new connection: [Errno 101] Network is unreachable')': /bottokenbot/sendMessage
2020-01-17 21:58:06,377: Retrying (Retry(total=0, connect=None, read=None, redirect=0, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f094da4c810>: Failed to establish a new connection: [Errno 101] Network is unreachable')': 

Tags: tononenewbyobjectisnetworkconnection
1条回答
网友
1楼 · 发布于 2024-09-28 22:04:58

更新

您实际上可以部署到heroku,即使使用免费帐户,它似乎对your_app.herokuapp.com之类的域使用通配符证书。这是在webhook配置中使用库python-telegram-bot,如documented here

我很确定heroku的证书是通配符,所以我不确定Telegram是否改变了他们的系统,允许使用通配符证书Their official documentation仍然建议不允许使用通配符证书


原始答案…

这种突然出现的对通配符证书缺乏支持的情况只会影响使用webhook支持构建的机器人程序(并且托管在具有通配符证书的域上)

可能有几种方法可以绕过这个问题:

  • 从bot中删除webhook支持。这可能是最不可取的,除非它是一个低流量的bot/供个人使用,并且您没有实现webhook支持是有原因的。如果没有webhook支持,您的机器人将作为客户端连接到telegrams API,而不是充当telegram系统连接到的服务器。此连接方法称为“轮询”

  • 转移到支持custom domains的付费python anywhere帐户。使用自定义域,您可以使用非通配符证书configure this。您可以从Let's Encrypt获得免费证书

当然,您可以借此机会移动到另一个主机,但要小心,因为许多类似的主机只支持其免费帐户的通配符证书:任何提供公共URL youraccount.provider.tld的主机

编辑

(*)我从这个问题推断,对通配符证书的限制突然/最近被引入,但据this answer称,这可以追溯到2017年3月。有关SSL配置的其他限制,请参见official docs

相关问题 更多 >