Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9117207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:51:07+00:00 2026-06-17T04:51:07+00:00

I wrote a python script to change passwords in AD that works well from

  • 0

I wrote a python script to change passwords in AD that works well from a command line. Now I am transferring that script to Django in order to make a change password page. Everything seems to work except one thing: for some reason, I keep getting a TypeError in Django that suggests a string rather than a unicode object should be passed to AD. Of course, when I do this, AD protests because the password is no longer in unicode. I’m guessing that I am overlooking something simple, but I cannot figure out what.

Below is the views.py code that I think should work (and that does work in the command line version). I added unicode() to the passwords just to indicate that they are in fact unicode, although they are definitely unicode before these lines.

import ldap
def changePassword(request):
    t = ldap.initialize(server) 
    . . .
    t.simple_bind_s('**********', '****')
    . . .
    mod_attrs = [(ldap.MOD_DELETE, 'unicodePwd', [unicode(oldPassword)]), 
                (ldap.MOD_ADD, 'unicodePwd', [unicode(newPassword)])]
    t.modify_s(dn, mod_attrs)

The error:

('expected a string in the list', u'pass!word')

     Request Method:   POST
      Request URL:     http://127.0.0.1:8000/index/
     Django Version:   1.4.2
     Exception Type:   TypeError
    Exception Value:
                       ('expected a string in the list', u'pass!word')

   Exception Location: /usr/lib/python2.7/dist-packages/ldap/ldapobject.py
                       in _ldap_call, line 96
   Python Executable:  /usr/bin/python
     Python Version:   2.7.3

The modified version does not raise an exception but also does not change the password (because the password is not passed in unicode):

mod_attrs = [(ldap.MOD_DELETE, 'unicodePwd', [str(oldPassword)]), 
            (ldap.MOD_ADD, 'unicodePwd', [str(newPassword)])]
t.modify_s(dn, mod_attrs)

Does anyone know what might lead to this unicode issue? If I could prevent the exception in Django and keep the unicode, I think this code would work.

Thanks in advance for any insight you might be able to offer.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T04:51:09+00:00Added an answer on June 17, 2026 at 4:51 am

    This seems to be a problem with the Python LDAP module in general. A quick fix is to convert all Unicode strings with str(). I could store attributes including passwords this way in an OpenLDAP directory. I was using python.ldap directly, not through Django.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a python script that will change my cwd to
I wrote a Python script that does some task to generate, and then keep
I wrote a Python GUI script with Tkinter, and now I want to convert
I've recently started learning Python and wrote a little script that informs me when
I am trying to write a python script that checks out a revision from
I have a script that I wrote in python for testing out the sorting
I have python script that works fine but only when run as stand-alone, while
I wrote a Python script that I need to have installed on Windows Server
So I wrote a little script in python that brings up a gui with
I wrote the following script, which generates a SyntaxError : #!/usr/bin/python print Enter the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.