GVKun编程网logo

Golang和MongoDb远程访问失败(服务器在SASL身份验证步骤上返回错误:身份验证失败。)

25

本文将分享Golang和MongoDb远程访问失败的详细内容,并且还将对服务器在SASL身份验证步骤上返回错误:身份验证失败。进行详尽解释,此外,我们还将为大家带来关于Connect-MsolServ

本文将分享Golang和MongoDb远程访问失败的详细内容,并且还将对服务器在SASL身份验证步骤上返回错误:身份验证失败。进行详尽解释,此外,我们还将为大家带来关于Connect-MsolService:身份验证错误:意外的身份验证失败、Django Mongodb引擎:身份验证,会话和用户模型、Django Rest-身份验证失败时如何返回自定义json响应?、Django-使用mongoengine DB进行身份验证的相关知识,希望对你有所帮助。

本文目录一览:

Golang和MongoDb远程访问失败(服务器在SASL身份验证步骤上返回错误:身份验证失败。)

Golang和MongoDb远程访问失败(服务器在SASL身份验证步骤上返回错误:身份验证失败。)

我正在尝试使用mgo库从Go连接到远程MongoDB数据库(Mongolab),但出现错误panic: server returned error onSASL authentication step: Authentication failed。这是我的代码

package mainimport (    "fmt"    "gopkg.in/mgo.v2"    "gopkg.in/mgo.v2/bson"    "log")type Person struct {    Name  string    Phone string}func main() {    session, err := mgo.Dial("mongodb://<dbusername>:<dbpassword>@ds055855.mlab.com:55855")    if err != nil {        panic(err)    }    defer session.Close()    // Optional. Switch the session to a monotonic behavior.    session.SetMode(mgo.Monotonic, true)    c := session.DB("catalog").C("History")    err = c.Insert(&Person{"Ale", "+55 53 8116 9639"},        &Person{"Cla", "+55 53 8402 8510"})    if err != nil {        log.Fatal(err)    }    result := Person{}    err = c.Find(bson.M{"name": "Ale"}).One(&result)    if err != nil {        log.Fatal(err)    }    fmt.Println("Phone:", result.Phone)}

我怎样才能解决这个问题?当然,我在代码中使用星号和密码代替星号。

答案1

小编典典

请检查是否为Mongolab数据库实例添加了用户(如果数据库名称为,则为https://mongolab.com/databases/catalog#userscatalog),因为默认情况下,用户列表为空(帐户user
/ password!=数据库)用户密码)。

还要/<databasename>在连接字符串末尾添加mongodb://*******:*******@ds045795.mongolab.com:45795/databasename

Connect-MsolService:身份验证错误:意外的身份验证失败

Connect-MsolService:身份验证错误:意外的身份验证失败

不能在参数中输入密码,因为用户使用MFA登录,而不是用户名/密码,你应该让它弹出登录框并触发 MFA。

这里有一个 similar problem。

Django Mongodb引擎:身份验证,会话和用户模型

Django Mongodb引擎:身份验证,会话和用户模型

我是Django的新手,Mongodb看起来很酷,而且我有一些
问题!我正在使用Django nonrel和Django Mongodb引擎.
我希望我不会犯太多错误:)

1)是Django用户认证系统和Django会话
系统工作正常?因为我在allbuttonspressed.com上看到了
身份验证和管理界面存在问题
部分与第三方书面认证后端让我思考
django身份验证系统不能与mongodb一起使用:

You can only edit users in the admin interface if you add
“djangotoolBox” to your INSTALLED_APPS. Otherwise you’ll get an
exception about an unsupported query which requires JOINs.

Florian Hahn has also written an authentication backend which provides
permission support on non-relational backends. You should use that
backend if you want to use Django’s permission system.

2)如果身份验证系统正常,我该如何添加字段
用户模型?我在Django文档上看到了实现这一目标的方法
要去的是用OnetoOnefield定义一个模型到用户模型
(“user = models.OnetoOneField(User)”)并定义我们的其他字段
想要那个模特.我认为它必须是sql的正确方法
数据库.但是像Nolong这样的mongodb对我来说似乎不对,如果
我没弄错,它创建了一个新的集合并放入每个文档
用于将文档链接到用户文档的用户字段
集合(完全像外键).这似乎不是一个
Nosql方式(嗯,这只是我的感觉,但因为我只是一个
初学者我可能错了,不要犹豫纠正我).有没有
建议直接向用户模型添加字段的方法?

3)当在Django中使用Model时,它将所有字段放入
文件,即使它们是空的吧?这不是浪费空间
如果它们是空的,写下文档中的很多字段名称?

4)这个问题更多的是关于Mongodb本身而不是引擎,但我会
不管怎么说,你可能会得到答案:多少空间呢
采取索引集合中的字段?

没想到我会这么写,我希望你们有些人有
勇气读我!

提前致谢,

Nolhian

解决方法

只有部分答案,因为我不使用MongoDB.

>我在Google AppEngine项目中使用django-nonrel.我正在使用其他自定义应用程序,如“djangotoolBox”,以及GAE的一些后端.管理面板和标准Django身份验证工作得非常好.我怀疑MongoDB是一样的(就像你提供的报价中提到的那样)
>你是对的.标准方法绝对适用于关系数据库,但对Nosql数据库可能无效或无效.典型的情况是将数据复制到另一个表,因此您不必执行JOIN.我认为您可以简单地将User模型子类化并将您的字段添加到自定义模型(docs).

Django Rest-身份验证失败时如何返回自定义json响应?

Django Rest-身份验证失败时如何返回自定义json响应?

您可以使用JsonResponse

from django.http import JsonResponse

def process_request(self,request):
    ...
    return JsonResponse({'error': 'authentication failed'})

Django-使用mongoengine DB进行身份验证

Django-使用mongoengine DB进行身份验证

我想使用mongoengine db在Django项目中处理身份验证。

我尝试了一些有关此问题的示例,这些问题已在旧问题中得到解答,但并未运行。我正在使用Django
1.6和mongoengine。一切都已安装,运行,并且我可以创建文档并将其保存到Mongoengine DB。

我正在追踪http://mongoengine-
odm.readthedocs.org/en/latest/django.html

我得到以下错误:

当我跑步时:

>>> from django.contrib.auth.models import User>>> user = User.objects.create_user(''john'', ''lennon@thebeatles.com'', ''johnpassword'')

我得到这个:

Traceback (most recent call last):  File "<console>", line 1, in <module>  File "/REBORN/reb_env/local/lib/python2.7/site-packages/django/db/models/manager.py", line 273, in __get__    self.model._meta.object_name, self.model._meta.swappedAttributeError: Manager isn''t available; User has been swapped for ''mongo_auth.MongoUser''>>>

我真的不明白两件事:

-是否必须创建并定义将存储用户的数据库,否则将自动创建用户?

-经理是什么?我还没有定义任何经理的东西

在开始的时候,我认为寄存器已保存在数据库中。调用了“ mongo_auth.MongoUser”,但没有将其保存在任何地方。

这是模型:

# Create your models here.from mongoengine import *class Profile(Document):    email = StringField(required=True)    first_name = StringField(max_length=50)    last_name = StringField(max_length=50)class auth_user(Document):    username = StringField(max_length=50)    email = StringField(max_length=50)    password = StringField(max_length=50)

settings.py已按照手册所述正确配置。

编辑@cestDiego:

我的设置完全相同,我注意到了Db后端,因为它创建了一个我不感兴趣的数据库,因为我使用mongo
…无论如何,我现在使用的是mongoengine.django.auth import用户,但是当我尝试时创建一个用户,它返回我:

>>> user = User.objects.create_user(''john'', ''lennon@thebeatles.com'', ''johnpassword'')Traceback (most recent call last):  File "<console>", line 1, in <module>AttributeError: ''QuerySet'' object has no attribute ''create_user''

也许我们正在自定义身份验证,这就是为什么不起作用,不知道的原因。你也有这个问题吗?

第二编辑:

我正在阅读,配置正确的设置后,我们必须使用Django的auth,就像我们所做的一样。

然后必须从django.contrib.auth导入import
authenticate并使用Django文档中提供的authenticate,希望对您有所帮助。

from django.shortcuts import render# Create your views here.from django.http import HttpResponsefrom game.models import *from mongoengine import *from models import Userfrom django.contrib.auth import authenticatedef login(request):        user = authenticate(username=''john'', password=''secret'')        if user is not None:            # the password verified for the user            if user.is_active:                print("User is valid, active and authenticated")            else:                print("The password is valid, but the account has been disabled!")        else:            # the authentication system was unable to verify the username and password            print("The username and password were incorrect.")

答案1

小编典典

我解决问题

在Django 1.6中…

我的settings.py看起来像这样:

"""Django settings for prova project.For more information on this file, seehttps://docs.djangoproject.com/en/1.6/topics/settings/For the full list of settings and their values, seehttps://docs.djangoproject.com/en/1.6/ref/settings/"""# Build paths inside the project like this: os.path.join(BASE_DIR, ...)import osBASE_DIR = os.path.dirname(os.path.dirname(__file__))# Quick-start development settings - unsuitable for production# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/# SECURITY WARNING: keep the secret key used in production secret!SECRET_KEY = ''^%r&tw5_steltu_ih&n6lvht0gs(0p#0p5z0br@+#l1o(iz_t6''# SECURITY WARNING: don''t run with debug turned on in production!DEBUG = TrueTEMPLATE_DEBUG = TrueALLOWED_HOSTS = []# Application definitionINSTALLED_APPS = (    ''django.contrib.admin'',    ''django.contrib.auth'',    ''django.contrib.contenttypes'',    ''django.contrib.sessions'',    ''django.contrib.messages'',    ''django.contrib.staticfiles'',    ''django.contrib.sessions'',)MIDDLEWARE_CLASSES = (    ''django.contrib.sessions.middleware.SessionMiddleware'',    ''django.middleware.common.CommonMiddleware'',    ''django.middleware.csrf.CsrfViewMiddleware'',    ''django.contrib.auth.middleware.AuthenticationMiddleware'',    ''django.contrib.messages.middleware.MessageMiddleware'',    ''django.middleware.clickjacking.XFrameOptionsMiddleware'',    ''django.contrib.sessions.middleware.SessionMiddleware'',)ROOT_URLCONF = ''prova.urls''WSGI_APPLICATION = ''prova.wsgi.application''# Database# https://docs.djangoproject.com/en/1.6/ref/settings/#databasesDATABASES = {    ''default'': {        ''ENGINE'': ''django.db.backends.dummy''    }}AUTHENTICATION_BACKENDS = (    ''mongoengine.django.auth.MongoEngineBackend'',)SESSION_ENGINE = ''mongoengine.django.sessions''SESSION_SERIALIZER = ''mongoengine.django.sessions.BSONSerializer''# Internationalization# https://docs.djangoproject.com/en/1.6/topics/i18n/LANGUAGE_CODE = ''en-us''TIME_ZONE = ''UTC''USE_I18N = TrueUSE_L10N = TrueUSE_TZ = True# Static files (CSS, JavaScript, Images)# https://docs.djangoproject.com/en/1.6/howto/static-files/STATIC_URL = ''/static/''

和我的views.py看起来像:

from django.shortcuts import render# Create your views here.from django.http import HttpResponsefrom game.models import *  from mongoengine import *#from django.contrib.auth import authenticatefrom mongoengine.django.auth import Userdef login(request):    connect(''reborn'')    from django.contrib.auth import login    from mongoengine.django.auth import User    from mongoengine.queryset import DoesNotExist    from django.contrib import messages    try:        user = User.objects.get(username=''bob'')#request.POST[''username''])        if user.check_password(''bobpass''):#request.POST[''password'']):            user.backend = ''mongoengine.django.auth.MongoEngineBackend''            print login(request, user)            request.session.set_expiry(60 * 60 * 1) # 1 hour timeout            print "return"            return HttpResponse("LOGUEJAT")#redirect(''index'')        else:            print "malament"            messages.add_message(request,messages.ERROR,u"Incorrect login name or password !")    except DoesNotExist:        messages.add_message(request,messages.ERROR,u"Incorrect login name or password !")    return render(request, ''login.html'', {})def logout(request):#NOT TESTED    from django.contrib.auth import logout    logout(request)    return redirect(''login'')def createuser(request):     connect(''reborn'')    User.create_user(''boba'',''bobpass'',''bobsaget@fullhouse.gov'')    return HttpResponse("SAVED")

现在,用户对象保存在数据库中,如下所示:

{    "_id" : ObjectId("53465fa60f04c6552ab77475"),    "_cls" : "User",    "username" : "boba",    "email" : "bobsaget@fullhouse.gov",    "password" : "pbkdf2_sha256$12000$ZYbCHP1K1kDE$Y4LnGTdKhh1irJVktWo1QZX6AlEFn+1daTEvQAMMehA=",    "is_staff" : false,    "is_active" : true,    "is_superuser" : false,    "last_login" : ISODate("2014-04-10T09:08:54.551Z"),    "date_joined" : ISODate("2014-04-10T09:08:54.550Z"),    "user_permissions" : [ ]}

今天的关于Golang和MongoDb远程访问失败服务器在SASL身份验证步骤上返回错误:身份验证失败。的分享已经结束,谢谢您的关注,如果想了解更多关于Connect-MsolService:身份验证错误:意外的身份验证失败、Django Mongodb引擎:身份验证,会话和用户模型、Django Rest-身份验证失败时如何返回自定义json响应?、Django-使用mongoengine DB进行身份验证的相关知识,请在本站进行查询。

本文标签: