mongoDB有不同的认证机制,3.0版本以后采用的是'MONGODB-CR', 之前的版本采用的是'MONGODB-CR'。

所以,以我的版本情况,显然应该用'SCRAM-SHA-1'

from pymongo import MongoClient
host = '127.0.0.1'
client = MongoClient(host, )
#连接mydb数据库,账号密码认证
db = client.admin # 先连接系统默认数据库admin
# 下面一条更改是关键,我竟然尝试成功了,不知道为啥,先记录下踩的坑吧
db.authenticate("root", "",mechanism='SCRAM-SHA-1') # 让admin数据库去认证密码登录,好吧,既然成功了,
my_db = client.mydb # 再连接自己的数据库mydb
collection = my_db.myset # myset集合,同上解释
collection.insert({"name":"zhangsan","age":}) # 插入一条数据,如果没出错那么说明连接成功
for i in collection.find():
print(i)

pymongo.errors.OperationFailure: Authentication failed.的更多相关文章

  1. 使用pymongo连接mongodb时报错:pymongo.errors.OperationFailure: not authorized

    连接本机或局域网部署的mongodb时可以用以下方法: from urllib import parse from pymongo import MongoClient host = '*.*.*.* ...

  2. smtplib.SMTPAuthenticationError: (535, b'Error: authentication failed')解决办法

    raise SMTPAuthenticationError(code, resp) smtplib.SMTPAuthenticationError: (535, b'Error: authentica ...

  3. javaMail使用163邮箱报535 Error: authentication failed

    javaMail使用网易163邮箱或者是126或者是网易其他邮箱报535 Error: authentication failed javax.mail.AuthenticationFailedExc ...

  4. github提交失败并报错java.io.IOException: Authentication failed:

    一.概述 我最近在写一个android的项目. 软件:android studio.Android studio VCS integration(插件) Android studio VCS inte ...

  5. IndexOf("authentication failed") > -1

    if (e.Value.Error.Message.IndexOf("authentication failed") > -1)   {      strFailMessag ...

  6. (转载)postgresql navicat 客户端连接验证失败解决方法:password authentication failed for user

    命令:su - postgres CREATE USER foo WITH PASSWORD 'secret'; ==================== 1.2个配置修改 postgresql.co ...

  7. pgadmin3 新建服务器出现错误 Peer authentication failed for user "postgres" 的解决办法

    转自:http://blog.csdn.net/tingyuanss/article/details/43763899 用pgadmin3 新建服务器出现错误 Peer authentication ...

  8. MongoDB3.4安装配置以及与Robomongo1.1的连接——解决Authentication Failed导致的不能连接问题

    本文环境:win10(64)+MongoDB(3.4.5)+Robomongo(1.1) 目录: MongoDB的安装 MongoDB的配置 Robomongo的安装以及与MongoDB的连接 一些新 ...

  9. fatal: Authentication failed for “someurl”

    一.前言 我们在公司做项目,很多时候会遇到这个问题:Git failed with a fatal error. Authentication failed for ‘ http// xxx..... ...

随机推荐

  1. Python爬虫——小说

    #encoding:utf8 import re import urllib2 url = 'http://www.23us.com/html/55/55304/' request = urllib2 ...

  2. Shell生成数字序列

    转自http://kodango.com/generate-number-sequence-in-shell Shell里怎么输出指定的数字序列: for i in {1..5}; do echo $ ...

  3. socket:10038错误

    转自:http://blog.csdn.net/chen495810242/article/details/42029825 winSock的一个bug:当closesocket多次错误使用时会导致问 ...

  4. NLTK 知识整理

    NLTK 知识整理 nltk.corpus模块自带语料 NLTK comes with many corpora, toy grammars, trained models, etc. A compl ...

  5. UI自动化(二)css选择器

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  6. ldap集成nexus

    nexus版本:2.14.4 添加nexus支持ldap认证: 管理员登录,点击 Administration --> Server -->Security Settings,将 OSS ...

  7. 让CSS某行不失效

    比如百度的分享代码 <div id="bdshare" class="bdshare_t bds_tools get-codes-bdshare"> ...

  8. vector at()函数比 []运算符操作安全

    转载:https://blog.csdn.net/chenjiayi_yun/article/details/18507659 []操作符的源码 reference operator[](size_t ...

  9. Junit Framework -TestRule,自动化测试中如何再次运行失败的测试用例

    有时由于服务器,浏览器等问题,会导致自动化测试用例运行失败,此处通过案例讲解如何使用Junit框架中的TestRule来实现重复运行失败的测试用例. 首先定义一个类并让它实现TestRule,代码如下 ...

  10. freeswitch刷新网关方法汇总

    1.freeswitch xml配置文件新增网关后,使其生效,可以重启freeswitch或者使用命令方式 fs_cli -H 127.0.0.1 -P 8021 -p hmzj -x sofia p ...