1

我正在为我的不和谐机器人使用 MongoDB 地图集,但最近遇到了一个错误。在托管(Heroku)上一切正常,我首先更新了所有模块,但错误并没有消失。我使用电机作为驱动程序来处理 MongoDB 地图集。检查数据库连接URL,一切正常。

Python 3.10 版(也在 Heroku 上)

Traceback (most recent call last):
  File "D:\Проекты\AkainuBot\main.py", line 23, in <module>
    mongo = AsyncIOMotorClient(
  File "D:\Python\lib\site-packages\motor\core.py", line 159, in __init__
    delegate = self.__delegate_class__(*args, **kwargs)
  File "D:\Python\lib\site-packages\pymongo\mongo_client.py", line 718, in __init__
    self.__options = options = ClientOptions(
  File "D:\Python\lib\site-packages\pymongo\client_options.py", line 165, in __init__
    self.__pool_options = _parse_pool_options(options)
  File "D:\Python\lib\site-packages\pymongo\client_options.py", line 132, in _parse_pool_options
    ssl_context, ssl_match_hostname = _parse_ssl_options(options)
  File "D:\Python\lib\site-packages\pymongo\client_options.py", line 98, in _parse_ssl_options
    ctx = get_ssl_context(
  File "D:\Python\lib\site-packages\pymongo\ssl_support.py", line 159, in get_ssl_context
    ctx.load_verify_locations(certifi.where())
  File "D:\Python\lib\site-packages\pymongo\pyopenssl_context.py", line 276, in load_verify_locations
    self._callback_data.trusted_ca_certs = _load_trusted_ca_certs(cafile)
  File "D:\Python\lib\site-packages\pymongo\ocsp_support.py", line 79, in _load_trusted_ca_certs
    _load_pem_x509_certificate(cert_data, backend))
  File "D:\Python\lib\site-packages\cryptography\x509\base.py", line 436, in load_pem_x509_certificate
    return rust_x509.load_pem_x509_certificate(data)
ValueError: error parsing asn1 value: ParseError { kind: InvalidValue, location: ["RawCertificate::tbs_cert", "TbsCertificate::serial"] }
4

1 回答 1

1

通过在 MongoClient 上添加 ssl_cert_reqs 选项(并且显然导入 ssl),我解决了解析 asn1 值错误的问题。

dbClient = pymongo.MongoClient(uri, ssl_cert_reqs=ssl.CERT_NONE)
于 2021-11-14T19:42:04.980 回答