You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu 20.04下Python Telegram Bot SSL证书验证失败求助

解决Telegram Bot SSL证书验证失败问题(Ubuntu 20.04)

根据你描述的情况,服务器系统根证书大概率出现缺失或损坏,导致无法验证Telegram API的SSL证书,以下是具体修复步骤:

1. 重置系统根证书

Ubuntu 20.04通过ca-certificates包管理全局根证书,执行以下命令重新安装并更新证书:

sudo apt update
sudo apt install --reinstall ca-certificates
sudo update-ca-certificates --fresh

该操作会恢复系统默认的可信根证书集合,强制刷新证书存储。

2. 验证修复效果

修复完成后,先通过curl测试Telegram API的SSL连接:

curl -I https://api.telegram.org

若返回HTTP/1.1 200 OK,说明证书验证正常。再用Firefox访问该地址,确认不再提示连接不安全。

3. 重启Bot脚本

证书修复后,重启你的Telegram Bot脚本,检查send_message调用是否正常执行。

额外排查(若上述步骤无效)

  • 检查代理/防火墙:如果服务器使用代理或防火墙,确认是否拦截了SSL连接,可临时关闭代理测试。
  • 更新Python证书库:你的环境使用certifi提供证书,尝试更新该库:
pip3 install --upgrade certifi

内容的提问来源于stack exchange,提问作者puppet

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.03 17:01:21