【问题标题】:“SSL: CERTIFICATE_VERIFY_FAILED” error in my python telegram bot我的 python 电报机器人中的“SSL:CERTIFICATE_VERIFY_FAILED”错误
【发布时间】:2020-04-21 04:52:01
【问题描述】:

我的 Telegram 机器人代码在几周内都可以正常工作,但今天我没有更改任何内容,突然我收到 [SSL: CERTIFICATE_VERIFY_FAILED] 错误,并且我的机器人代码不再在我的 PC 中工作。我使用的是 Ubuntu 16.04,我正在使用 python 电报机器人库。

出了什么问题以及如何解决?

我的错误日志:

0|main_fil |   File "/home/angel/.local/lib/python3.6/site-packages/telegram/ext/jobqueue.py", line 314, in start
0|main_fil |     name="Bot:{}:job_queue".format(self._dispatcher.bot.id))
0|main_fil |   File "/home/angel/.local/lib/python3.6/site-packages/telegram/bot.py", line 54, in decorator
0|main_fil |     self.get_me()
0|main_fil |   File "<decorator-gen-1>", line 2, in get_me
0|main_fil |   File "/home/angel/.local/lib/python3.6/site-packages/telegram/bot.py", line 70, in decorator
0|main_fil |     result = func(*args, **kwargs)
0|main_fil |   File "/home/angel/.local/lib/python3.6/site-packages/telegram/bot.py", line 292, in get_me
0|main_fil |     result = self._request.get(url, timeout=timeout)
0|main_fil |   File "/home/angel/.local/lib/python3.6/site-packages/telegram/utils/request.py", line 277, in get
0|main_fil |     result = self._request_wrapper('GET', url, **urlopen_kwargs)
0|main_fil |   File "/home/angel/.local/lib/python3.6/site-packages/telegram/utils/request.py", line 231, in _request_wrapper
0|main_fil |     raise NetworkError('urllib3 HTTPError {0}'.format(error))
0|main_fil | telegram.error.NetworkError: urllib3 HTTPError [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)

我也试过 curl:

 curl -X POST -H 'Content-Type: application/json'  -d '{"chat_id": "******", "text": "Test", "disable_notification": true}'  https://api.telegram.org/bot*****************/sendMessage

返回这个错误

curl: (60) SSL certificate problem: self signed certificate in certificate chain
More details here: https://curl.haxx.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.

在他们说将 urllib3 降级到 1.24.1 的一些帖子中,我修改它但仍然是同样的错误。 我在本地使用相同的机器人令牌运行脚本并且它运行正常

还有这个

angel@***:/$ python3 -m telegram
python-telegram-bot 12.6.1
certifi 2020.04.05.1
future 0.18.2
Python 3.6.8 (default, Oct  7 2019, 12:59:55)  [GCC 8.3.0]

【问题讨论】:

标签: python telegram-bot python-telegram-bot


【解决方案1】:

不是答案,但它可以启动你的机器人。

在这个文件中:

AppData\Local\Programs\Python\Python39\Lib\site-packages\telegram\utils\request.py

在第 140-150 行,您可以找到类似的内容

    kwargs = dict(
        maxsize=con_pool_size,
        cert_reqs='CERT_REQUIRED',
        ca_certs=certifi.where(),
        socket_options=sockopts,
        timeout=urllib3.Timeout(connect=self._connect_timeout, read=read_timeout, total=None),
    )

这样做,它就会起作用:

    urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
    kwargs = dict(
        maxsize=con_pool_size,
        cert_reqs='CERT_NONE',
        ca_certs=certifi.where(),
        socket_options=sockopts,
        timeout=urllib3.Timeout(connect=self._connect_timeout, read=read_timeout, total=None),
    )

有警告,但有效 =)

【讨论】:

    猜你喜欢
    • 2019-10-06
    • 2023-03-17
    • 1970-01-01
    • 1970-01-01
    • 2018-02-27
    • 1970-01-01
    • 2015-12-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多