You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by James Brady <ja...@gmail.com> on 2008/02/02 07:30:55 UTC

Unicode bug in python client code

Hi all,
I was adding passing python unicode objects to solr.add and got these  
sort of errors:
...
   File "/Users/jamesbrady/Documents/workspace/YelServer/yel/ 
solr.py", line 152, in add
     self.__add(lst,fields)
   File "/Users/jamesbrady/Documents/workspace/YelServer/yel/ 
solr.py", line 146, in __add
     lst.append(self.escapeVal(str(v)))
UnicodeEncodeError: 'ascii' codec can't encode characters in position  
30-31: ordinal not in range(128)

Here's a diff which properly checks the object type before calling str 
():
142a143,146
 >       if not isinstance(f, basestring):
 >         f = str(f)
 >       if not isinstance(v, basestring):
 >         v = str(v)
144c148
<       lst.append(self.escapeKey(str(f)))
---
 >       lst.append(self.escapeKey(f))
146c150
<       lst.append(self.escapeVal(str(v)))
---
 >       lst.append(self.escapeVal(v))

Keep up the good work - loving Solr so far!
James