473,624 Members | 2,185 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Convert Active Directory Object to string

Hi!

When I receive data from Microsoft Active Directory it is an
"ad_object" and has the type unicode. When I try to convert it to a
string I get this error:
UnicodeEncodeEr ror: 'ascii' codec can't encode character u'\xfc' in
position 26: ordinal not in range(128)

This is caused by characters like the german ä, ö or ü.

But I (think I) need this as a string. Is there a simple solution???

regards
Dirk

Jan 17 '06 #1
4 2816
Dirk Hagemann wrote:
When I receive data from Microsoft Active Directory it is an
"ad_object" and has the type unicode. When I try to convert it to a
string I get this error:
UnicodeEncodeEr ror: 'ascii' codec can't encode character u'\xfc' in
position 26: ordinal not in range(128)

This is caused by characters like the german ä, ö or ü.

But I (think I) need this as a string. Is there a simple solution???


A Unicode string is also a string.

If you want an 8-bit string, you need to decide what encoding you want to
use. Common encodings are us-ascii (which is the default if you convert from
unicode to 8-bit strings in Python), ISO-8859-1 (aka Latin-1), and UTF-8.
For example, if you want Latin-1 strings, you can use one of.

s = u.encode("iso-8859-1") # fail if some character cannot be converted
s = u.encode("iso-8859-1", "replace") # instead of failing, replace with ?
s = u.encode("iso-8859-1", "ignore") # instead of failing, leave it out

If you want an ascii string, replace "iso-8859-1" above with "ascii".

If you want to output the data to a web browser or an XML file, you can use

import cgi
s = cgi.escape(u).e ncode("ascii", "xmlcharrefrepl ace")

</F>

Jan 17 '06 #2
Hi Fredrik!

I think this will help me. I just have to do the same for danish
encoding and may be some further encondings...

Thanks!
Dirk

Jan 18 '06 #3
Ok - this really works well for german special characters, but what to
do with all the other encodings.
What I could do is to try to vonvert it to latin-1 and if it fails I
try latin-2 and so on. But is this really necessary? Isn't there may me
a module which can do this for me and returns a string?

What I want to do in the end is the following: I get some data from
Active Directory, then I create a SQL-statement including this data and
write this into the database.

regards
Dirk

Jan 18 '06 #4
Dirk Hagemann wrote:

What I want to do in the end is the following: I get some data from
Active Directory, then I create a SQL-statement including this data and
write this into the database.


Which API and protocol are you using to access Active Directory?

If you access it via LDAP (e.g. using python-ldap) you will get back
UTF-8 strings for textual attributes.

Ciao, Michael.
Jan 19 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2785
by: microsoft | last post by:
Hi People, when I try to modify an active directory user programatically, I receive the following exception: The server is unwilling to process the request Reading the microsoft web site, I found this article: http://support.microsoft.com/default.aspx?scid=kb;EN-US;248717 that says the following: ..........................
10
5427
by: huzz | last post by:
I have web application that quaries the Active Directory to get user details.. everything works fine but someday I'll get System.Runtime.InteropServices.COMExection and if I restart the client machine then it works again. here is one of the method where am calling the AD public bool UserExist(string UserName) {
4
3866
by: ASGMikeG | last post by:
Hi, How do I find the user object for the current user in Active Directory i.e. the user running my program ? Regards Michael
1
4743
by: Andrew | last post by:
Hey all, Working on revamping our Intranet here and making use of the LDPA, Active Directory, Directory Services, etc. that .Net provides. I am still fairly new on this subject, so the problem I have run into I am not sure how to fix, and really not sure what is causing it. Here's what is going on (test server - Windows 2003 Server): I have a page in a folder (under anonymous authentication in IIS6) that has a link on it that...
1
3890
by: tangus via DotNetMonster.com | last post by:
Hello all, I'm really struggling with getting some Active Directory code to work in ASP.NET. Can you please provide assistance? I am executing the following code: Dim enTry As DirectoryEntry = New DirectoryEntry("LDAP://domain") Dim mySearcher As New DirectorySearcher(enTry) Dim resEnt As SearchResult mySearcher.Filter = ("(objectClass=*)") mySearcher.SearchScope = SearchScope.Subtree
10
4045
by: Hriday | last post by:
Hi there, Please help me..It is urgent This is Hriday, working on windows authentication with Active Directory... My requirment is when a user sends a request to my web Applicatoin I want to Pop up windows Authentication box so that user will give his userId, Password & domain name for authenticaion. After that I want to take these three info of user and make a search in Active Directory.
2
4689
by: P Webster | last post by:
We recently moved a web site that validated user credentials in Active Directory from IIS 5.1 to IIS 6, and the validation code no longer works. The web.config file is set to Windows authentication because all we do is verify the user on the login form so we can redirect them to the appropriate page based on their group. The code to authenticate is: Public Function IsAuthenticated(ByVal domain As String, ByVal username As String, ByVal...
2
5959
by: Jim in Arizona | last post by:
My goal, somehow, is to populate a dropdownlist with all the user names in active directory. I don't even know where to begin, really. I added a reference to System.DirectoryServices so I could use the System.DirectoryServices.ActiveDirectory namespace. I don't even know if this is the right way to go as I can't seem to find anything in that namespace that would help me query active directory for names. I can't use an LDAP query...
0
1445
by: lairpr74 | last post by:
Hi, I got a console application that updates active directory users, the information to be updated in active directory comes from a database table. This is my problem: right now the application works if none of the objects like (telephoneNumber, department, etc..) to be updated into active directory are not null. If an object is null I get an error. I try with an if condition, it does not give any error but does not updates the object...
0
8234
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8172
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8677
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8620
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8474
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6110
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5563
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4079
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.