Форум сайта python.su
$ python test123.py
Traceback (most recent call last):
File "test123.py", line 9, in <module>
ldif_writer.unparse(dn, entry)
File "/usr/lib/python2.6/site-packages/ldif.py", line 195, in unparse
self._unparseAttrTypeandValue('dn',dn)
File "/usr/lib/python2.6/site-packages/ldif.py", line 142, in _unparseAttrTypeandValue
self._unfoldLDIFLine(': '.join([attr_type,attr_value]))
File "/usr/lib/python2.6/site-packages/ldif.py", line 107, in _unfoldLDIFLine
self._output_file.write(line)
File "/usr/lib/python2.6/io.py", line 1500, in write
s.__class__.__name__)
TypeError: can't write str to text stream
$ cat test123.py
# coding: utf-8
import io, ldif
o = io.StringIO()
ldif_writer = ldif.LDIFWriter(o)
dn='cn=Michael Stroeder,ou=Test'
entry={'objectClass':['top','person'],'cn':['Michael Stroeder'],'sn':['Stroeder']}
ldif_writer.unparse(dn, entry)
Офлайн
# coding: utf-8
import io, ldif
class StrIO(io.StringIO):
def write(self, a):
return io.StringIO.write(self, unicode(a))
o = StrIO()
ldif_writer = ldif.LDIFWriter(o)
dn='cn=Michael Stroeder,ou=Test'
entry={'objectClass':['top','person'],'cn':['Michael Stroeder'],'sn':['Stroeder']}
ldif_writer.unparse(dn, entry)
Офлайн