【问题标题】:Use MongoDB with python2将 MongoDB 与 python2 一起使用
【发布时间】:2021-09-20 13:30:03
【问题描述】:

我正在为一个项目使用 python2。我知道它很旧,但就灵活性而言,它对我的​​项目更好。 我需要将 MongoDB 连接到它,但是当我尝试连接时,它给了我一个错误:

File "/Users/user/Desktop/cartella senza nome 2/pymongo/mongo_client.py", line 366, in __init__
    raise ConnectionFailure(str(e))
pymongo.errors.ConnectionFailure: connection closed

这是我的脚本:

import pymongo
from pymongo import MongoClient
import dns

client = pymongo.MongoClient("mongodb://dbmacems:<passowrd>@cluster0-shard-00-00.sulle.mongodb.net:27017/scan?w=majority&authSource=admin")
db = client.test

也许这就是我使用 python2 的原因? 所以有一个解决方案,或者我可以使用类似的“网络”数据库,如用于 python2 的 MongoDB?

【问题讨论】:

    标签: python database mongodb


    【解决方案1】:

    您的连接字符串缺少tls URI 选项。小心地从 Atlas UI 复制它。

    【讨论】:

    • 我找不到使用此选项的方法四,你能用它修复我的代码吗?我最近也试过这个:cluster0-shard-00-00.sulle.mongodb.net:27017/scan?ssl=true&amp;replicaSet=atlas-rc8hx2-shard-0&amp;authSource=admin。回溯提到了 ssl / tls 选项,但我找不到如何设置...pymongo.errors.OperationFailure: command {'ismaster': 1} failed: no SNI name sent, make sure using a MongoDB 3.4+ driver/shell.我需要帮助
    • 使用最新的驱动程序版本。
    猜你喜欢
    • 1970-01-01
    • 2018-12-01
    • 2014-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-30
    相关资源
    最近更新 更多