Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'encoding': 0.05; 'encoded': 0.07; 'tries': 0.07; 'string': 0.09; 'encode': 0.09; 'parsed': 0.09; 'parsing': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'string;': 0.09; 'subject:module': 0.09; 'python': 0.11; '"default': 0.16; '315,': 0.16; 'bug:': 0.16; 'codec': 0.16; 'consequence,': 0.16; 'default)': 0.16; 'expects': 0.16; 'fails.': 0.16; 'ldif': 0.16; 'ordinal': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; "skip:' 60": 0.16; 'skip:p 40': 0.19; 'seems': 0.21; 'coding': 0.22; 'header:User-Agent:1': 0.23; 'unicode': 0.24; 'looks': 0.24; 'skip:" 40': 0.26; 'skip:" 20': 0.27; 'skip:_ 20': 0.27; 'header:X-Complaints-To:1': 0.27; 'character': 0.29; 'writes:': 0.31; 'file': 0.32; 'probably': 0.32; 'another': 0.32; 'could': 0.34; "can't": 0.35; 'problem.': 0.35; 'skip:s 30': 0.35; 'convert': 0.35; 'charset:us-ascii': 0.36; 'skip:o 20': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'skip:u 10': 0.60; 'skip:t 30': 0.61; 'simply': 0.61; 'back': 0.62; 'received:217': 0.63; 'real': 0.63; 'taking': 0.65; 'fails,': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: dieter Subject: Re: Ldap module and base64 oncoding Date: Mon, 27 May 2013 08:04:16 +0200 References: <78b0eafba002480aba586b54db86abfc@exch.activenetwerx.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Gmane-NNTP-Posting-Host: pd9e0be31.dip0.t-ipconnect.de User-Agent: Gnus/5.1008 (Gnus v5.10.8) XEmacs/21.4.22 (linux) Cancel-Lock: sha1:RE29v8KWu/ksSvODWxQ8lkTV5xs= X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 30 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1369634670 news.xs4all.nl 16012 [2001:888:2000:d::a6]:53581 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:46169 "Joseph L. Casale" writes: > ... > After parsing the data for a user I am simply taking a value from the ldif file and writing > it back out to another which fails, the value parsed is: > > officestreetaddress:: T3R0by1NZcOfbWVyLVN0cmHDn2UgMQ== > > > File "C:\Python27\lib\site-packages\ldif.py", line 202, in unparse > self._unparseChangeRecord(record) > File "C:\Python27\lib\site-packages\ldif.py", line 181, in _unparseChangeRecord > self._unparseAttrTypeandValue(mod_type,mod_val) > File "C:\Python27\lib\site-packages\ldif.py", line 142, in _unparseAttrTypeandValue > self._unfoldLDIFLine(':: '.join([attr_type,base64.encodestring(attr_value).replace('\n','')])) > File "C:\Python27\lib\base64.py", line 315, in encodestring > pieces.append(binascii.b2a_base64(chunk)) > UnicodeEncodeError: 'ascii' codec can't encode character u'\xdf' in position 7: ordinal not in range(128) > >> c:\python27\lib\base64.py(315)encodestring() > -> pieces.append(binascii.b2a_base64(chunk)) This looks like a coding bug: "chunk" seems to be a unicode string; "b2a_base64" expects an encoded string ("str/bytes"); as a consequence, Python tries to convert the unicode to "str" by encoding with its "default enconding" ("ascii" by default) - and fails. You could try to find out, why "chunk" is unicode (rather than "str"). That will probably bring you to the real problem.