Telegram 不再接受 pythonanywhere 中的通配符 certificates.Getting 错误

Telegram no longer accepting wildcard certificates.Getting error in pythonanywhere

当我在 pythonanywhere 上部署我的机器人时,我无法向我的机器人发送消息。由于官方 pythonanywhere 博客 link to the blog post 中提到的 telegram 不再支持通配符证书的原因,服务器出现无法访问的错误。如果有人知道这个问题的解决方案,请大家帮助我

  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')': 

更新

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

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


原答案...

突然* 缺乏对通配符证书的支持应该只会影响使用 webhook 支持构建的机器人(并托管在具有通配符证书的域上)。

可能有几个选项可以解决这个问题:

  • 从您的 bot 中删除 webhook 支持。这可能是最不受欢迎的,除非它是一个低流量机器人/供个人使用,并且您出于某种原因没有实现 webhook 支持。如果没有 webhook 支持,您的机器人将作为客户端连接到电报 API,而不是作为电报系统连接到的服务器。这种连接方式叫做"Polling".

  • 转移到付费 python anywhere 帐户,支持 custom domains. With a custom domain you could then configure this 非通配符证书。您可以从 Let's Encrypt 获取免费证书。

你当然可以借此机会转移到另一个主机,但要小心,因为许多类似的主机将只支持他们的免费帐户的通配符证书:任何给你 public URL共 youraccount.provider.tld

编辑

(*) 我从这个问题中推断出 suddenly/recently 引入了对通配符证书的限制,但是根据 this answer. See the official docs 的其他限制,这可以追溯到 2017 年 3 月SSL 配置。