title: LDAP CGI password reset HELP ME
body: <p>This is my first post on stackoverflow. I'm kinda stuck here on some code. I keep running into a type error decoding Unicode is not supported</p>
  
  <p>what I want to build is that an end user can reset his or hers password through a web portal.</p>
  
  <p>Could you guys please help me figure out how to fix this problem ?
  If you need more info please say I'm happy to provide it to you.</p>
  
  <p>Kind regards</p>
  
  <p>Joey </p>
  
  <pre><code>! /usr/bin/python
  # _*_ coding: utf-8 _*_
  from __future__ import unicode_literals
  import cgi
  import uuid
  import os
  import time
  import ldap
  import sys
  
  def index():
  print """Content-type: text/html
           &lt;meta charset="UTF-8"&gt;
  &lt;head&gt;
  &lt;/head&gt;
  
  &lt;h1&gt;Reseting password web program&lt;/h1&gt;"""
  #Declaring variables for the program for later use we could use input   fields.
  PASSWORD_ATTR = "utf-8"
  username="joey hendricks" # Username for the user we want to change the password for.
  user_dn = "CN=%s,OU=Admin,OU=Assengraaf,DC=Assengraaf,DC=nl" % username
  password = 'New12345' # New password for the user we want to change the passwordfor.
  attr_name = 'mobile'
  attr_val = '12345678'
  print """&lt;h1&gt;"""+username,password+"""&lt;/h1&gt;"""
  # Setting up connection tot the LDAP server we use a SSL engrypted connection to the server.
  # Without a SSL connection you could run into certain errors the avoid these we use SSL by defaul$
  ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
  conn = ldap.initialize("ldaps://192.168.210.1:636")
  conn.set_option(ldap.OPT_REFERRALS, 0)
  conn.set_option(ldap.OPT_PROTOCOL_VERSION, 3)
  conn.set_option(ldap.OPT_X_TLS,ldap.OPT_X_TLS_DEMAND)
  conn.set_option( ldap.OPT_X_TLS_DEMAND, True )
  conn.set_option( ldap.OPT_DEBUG_LEVEL, 255 )
  conn.simple_bind_s("administrator@assengraaf.nl","password") # Admin credentials to reset the pa$
  
  if conn.compare_s(user_dn, attr_name, attr_val):
       unicode_pass = unicode("\"" + password + "\"", "iso-8859-1")
       password_value = unicode_pass.encode("utf-8")
       add_pass = [(ldap.MOD_REPLACE, PASSWORD_ATTR, [password_value])]
       try:
           conn.modify_s(user_dn, add_pass)
           conn.unbind_s() # Cancel the connection freeing up recources
           print"&lt;p1&gt; Password set succesfull&lt;/p1&gt;"
  
       except ldap.LDAPError, e:
           sys.stderr.write('Error setting AD password for: ' + username + '\n')
           sys.stderr.write('Message: ' + str(e) + '\n')
           sys.exit(1)
           conn.unbind_s() # Cancel the connection freeing up recources
           print"&lt;p2&gt;Error setting password&lt;/p2&gt;"
  
  else:
     print"&lt;p3&gt;No match found&lt;/p3&gt;"
  </code></pre>
  
  <p>if <strong>name</strong> == '<strong>main</strong>':
      index()</p>