English 中文(简体)
采用python-ldap与现成目录的代码代码编码
原标题:Working with unicode encoded Strings from Active Directory via python-ldap

我已经谈到这一问题,但在经过一些测试之后,我决定提出一个新问题,其中有一些更为具体的信息:

我读到的是来自我们积极名录的Python-ldap(和A/63/32.7)。 这确实行之有效,但我有特殊问题。 他们确实像UTF-8一样,在圣经上印成编码。 目标是将其写成一个MySQL DB,但从一开始,我就没有把这些扼杀带入适当的UTF-8。

例(借用是我所有的自动取款权条目的阵列):

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])

第二次试验,用手法加插如下:

testentry = "Mxc3xbcller"
testentry.decode( utf-8 ,  ignore )
print testentry.encode( utf-8 ,  ignore )
print testentry.encode( latin1 ,  ignore )
print repr(testentry)

第一个例子:

Mxc3xbcller
Mxc3xbcller
u M\xc3\xbcller 

Edit:如果我尝试用......replace( ± )取代两重弹,产出不变。

第二个例子:

Müller
M�ller
 Mxc3xbcller 

是否有办法使反倾销产出适当编码? 我已经读过许多文件,但大家都说,LDAPv3严格地给你以编号的座标。 积极名录使用LDAPv3。

我的老问题在此是:

Edit: Added repr(s) infos

最佳回答

首先,知道 至Windows console常常是烟化数据的步骤,因此,为您的测试,请见 re repr(s),以便了解你在座右铭中的确切 by。

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.

执行:

科索沃,它希望你们重新获得一些.。 也许可以找到更好的办法,但不管怎样,你都可以适应,尽管情况很糟:

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.

问题回答

暂无回答




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签