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 6236703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:53:38+00:00 2026-05-24T10:53:38+00:00

I already came up with this problem, but after some testing I decided to

  • 0

I already came up with this problem, but after some testing I decided to create a new question with some more specific Infos:

I am reading user accounts with python-ldap (and Python 2.7) from our Active Directory. This does work well, but I have problems with special chars. They do look like UTF-8 encoded strings when printed on the console. The goal is to write them into a MySQL DB, but I don’t get those strings into proper UTF-8 from the beginning.

Example (fullentries is my array with all the AD entries):

fullentries[23][1].decode('utf-8', 'ignore')    
print fullentries[23][1].encode('utf-8', 'ignore')
print fullentries[23][1].encode('latin1', 'ignore')
print repr(fullentries[23][1])

A second test with a string inserted by hand as follows:

testentry = "M\xc3\xbcller"
testentry.decode('utf-8', 'ignore')
print testentry.encode('utf-8', 'ignore')
print testentry.encode('latin1', 'ignore')
print repr(testentry)

The output of the first example ist:

M\xc3\xbcller
M\xc3\xbcller
u'M\\xc3\\xbcller'

Edit: If I try to replace the double backslashes with .replace(‘\\\\’,’\\) the output remains the same.

The output of the second example:

Müller
M�ller
'M\xc3\xbcller'

Is there any way to get the AD output properly encoded? I already read a lot of documentation, but it all states that LDAPv3 gives you strictly UTF-8 encoded strings. Active Directory uses LDAPv3.

My older question this topic is here: Writing UTF-8 String to MySQL with Python

Edit: Added repr(s) infos

  • 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-05-24T10:53:38+00:00Added an answer on May 24, 2026 at 10:53 am

    First, know that printing to a Windows console is often the step that garbles data, so for your tests, you should print repr(s) to see the precise bytes you have in your string.

    You need to find out how the data from AD is encoded. Again, print repr(s) will let you see the content of the data.

    UPDATED:

    OK, it looks like you’re getting strange strings somehow. There might be a way to get them better, but you can adapt in any case, though it isn’t pretty:

    u.decode('unicode_escape').encode('iso8859-1').decode('utf8')
    

    You might want to look into whether you can get the data in a more natural format.

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

Sidebar

Related Questions

i already had 2008 express sql server but for some reason it came without
I know this question has been asked already but I would like to solve
This problem came up in the real world, but I've translated it into a
There's this already populated database which came from another dev. I'm not sure what
I have updated many records already, but when it came to a word that
I already know the obvious answer to this question: just download <insert favorite windows
I've been reading up on this whole subject, but I never came across this
This question came into my mind while generating sample data for a SO-answer. I
I am working my way through some samples, and came up with this working
Just when I was about to post this question, I came up with an

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.