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. router.go,router.push,router.replace的区别

    除了使用 <router-link> 创建 a 标签来定义导航链接,我们还可以借助 router 的实例方法,通过编写代码来实现.当你点击 <router-link> 时,这个 ...

  2. Selenium 常用定位对象元素的方法

    常见定位对象元素的方法 在使用selenium webdriver进行元素定位时,通常使用findElement或findElements方法结合By类返回的元素句柄来定位元素.其中By类的常用定位方 ...

  3. MyEclipse与Eclipse配置清单

    MyEclipse与Eclipse配置清单 1.编码设置    workspace -> 设置全局编码utf-8    修改JSP编码(Encoding)为UTF-82.Java配置    格式 ...

  4. nginx的gzip压缩功能

    我们在开发网站的时候,应该要考虑到pv,因为pv比较大可能会造成服务器带宽不够用,进而导致用户体验变差. 这个时候我们就可以考虑用nginx的gzip功能. 在nginx中开启gzip压缩功能很简单, ...

  5. Mysql 利用拷贝data目录文件的方式迁移mysql数据库

    Mysql 利用拷贝data目录文件的方式迁移mysql数据库 步骤如下: 1.首先要确定data目录 这个问题困扰了我很久,因为网上的帖子大部分只是说拷贝mysql数据库目录下的data文件夹中的数 ...

  6. Git pull的时候遇到问题

    转载:https://www.jianshu.com/p/7b1c58e0a9ef 使用git从远程pull代码时报错: error: The following untracked working ...

  7. 我写的RunTime函数之一,为类的某个属性赋值以及方法交换

      1,为属性赋值 #import <UIKit/UIKit.h> @interface UIViewController (RunTime) - (BOOL)setPropertyVal ...

  8. 在Linux系统安装Appium

    安装sudo apt-get update sudo apt-get install nodejs sudo apt-get install npm npm install -g appium 卸载: ...

  9. Android O HIDL的实现对接【转】

    本文转载自:https://blog.csdn.net/gh201030460222/article/details/80551897 Android O HIDL的实现对接1. HIDL的定义1.1 ...

  10. Golang初练手-多线程网站路径爆破

    以前用Python写过这个工具,前两天看了golang的基础,就想着用这个语言把这个工具重写一遍 先放张图 用法 Example : Buster.exe -u=https://www.baidu.c ...