【问题标题】:TypeError: All provided fields *must* be text when bytes mode is off; got 'CN=XXX,CN=Users,DC=domain,DC=com'TypeError:当字节模式关闭时,所有提供的字段*必须*是文本;得到'CN = XXX,CN =用户,DC =域,DC = com'
【发布时间】:2018-03-21 08:54:48
【问题描述】:

我正在尝试使用 django-ldapdb 库创建一个新模型。当我尝试运行 python manage.py makemigrations 时,它告诉我字节模式已关闭。我真的不知道这是在哪里以及如何激活它。

这是我的模型:

class LdapUser(ldapdb.models.Model):
    base_dn = "CN=XXX,CN=Users,DC=domain,DC=com"
    object_classes = ['posixAccount', 'shadowAccount', 'inetOrgPerson']

    phone = CharField(db_column='telephoneNumber', blank=True)
    mobile_phone = CharField(db_column='mobile', blank=True)

我查了一下,但找不到任何有用的东西。我希望有人可以帮助我。

提前致谢。

【问题讨论】:

    标签: python django python-2.7 django-models ldap


    【解决方案1】:

    尝试为base_dn 使用 unicode 字符串:

    base_dn = u"CN=XXX,CN=Users,DC=domain,DC=com"
    

    【讨论】:

    • 我该怎么做?
    • 这是您模型的第一行,只需添加u 前缀
    猜你喜欢
    • 1970-01-01
    • 2019-09-17
    • 2013-09-16
    • 1970-01-01
    • 1970-01-01
    • 2017-10-25
    • 2013-10-31
    • 1970-01-01
    • 2018-11-25
    相关资源
    最近更新 更多