【问题标题】:Problem connecting to mongodb atlas using python使用 python 连接到 mongodb atlas 的问题
【发布时间】:2021-12-29 11:53:40
【问题描述】:

我在连接到 Mongo 时遇到问题。 将不胜感激帮助.. 谢谢

client =MongoClient("mongodb+srv://srdht:srdht@srddataset.2htbr.mongodb.net/dbImages?retryWrites=true&w=majority",ssl=True,ssl_cert_reqs='CERT_NONE')
    db=client.get_database('dbImages')
    records = db.atopic
    records.count_documents({})
    new_student = {
        'name': 'ram',
        'roll_no': 321,
        'branch': 'it'
    }
    records.insert_one(new_student)
    new_students = [
        {
            'name': 'alex',
            'roll_no': 320,
            'branch': 'it'
        },
        {
            'name': 'john',
            'roll_no': 30,
            'branch': 'ece'
        }
    ]
    
    records.insert_many(new_students)

和错误:

Traceback (most recent call last):
  File "C:/Users/student/Documents/GitHub/SRD/imageProcessing.py", line 24, in <module>
    **client =MongoClient("mongodb+srv://srdht:srdht@srddataset.2htbr.mongodb.net/dbImages?retryWrites=true&w=majority",ssl=True,ssl_cert_reqs='CERT_NONE')**
  File "C:\Users\student\.windows-build-tools\python27\lib\site-packages\pymongo\mongo_client.py", line 672, in __init__
    connect_timeout=timeout)
  File "C:\Users\student\.windows-build-tools\python27\lib\site-packages\pymongo\uri_parser.py", line 453, in parse_uri
    **'%s -m pip install "pymongo[srv]"' % (python_path))
pymongo.errors.ConfigurationError: The "dnspython" module must be installed to use mongodb+srv:// URIs. To fix this error install pymongo with the srv extra:
 C:\Users\student\.windows-build-tools\python27\python.exe -m pip install "pymongo[srv]"**

【问题讨论】:

    标签: python mongodb


    【解决方案1】:

    你需要安装dnspython,试试这个命令安装:

    python -m pip install pymongo[srv]
    

    【讨论】:

    • 我试过了。我也尝试卸载并重新安装,但问题仍然存在
    • 我认为您使用的是非常旧的 python(2.7) 版本。您可以使用以下命令检查正在运行的版本:“python --version” 您必须将软件包安装在正确版本的 python 上:C:\Users\student\.windows-build-tools\python27\python.exe -m pip install " pymongo[srv]"
    • 我正在使用interapter 3.7,但仍然有同样的错误
    • 尝试在3.7上安装包:python3 -m pip install pymongo[srv]
    猜你喜欢
    • 1970-01-01
    • 2018-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-11
    • 1970-01-01
    • 2021-01-04
    相关资源
    最近更新 更多