UnicodeEncodeError: 'ascii' codec can't encode characters in position 7-8: ordinal not in range(128)

Issue #360 resolved
Vladislav Polukhin
created an issue

I use Whoosh==2.5.3 and python 2.7. My code:

from __future__ import unicode_literals

from whoosh import qparser
from whoosh.qparser import QueryParser
from project import ix


parser = QueryParser('name', schema=ix.schema)
parser.add_plugin(qparser.FuzzyTermPlugin())
parser.add_plugin(qparser.PhrasePlugin())
query = parser.parse('premium 1кг~')

raises:

Traceback (most recent call last):
  File "/home/nuklea/workspace/project/issue.py", line 38, in <module>
    query = parser.parse('premium 1кг~')
  File "/home/nuklea/.virtualenvs/project/lib/python2.7/site-packages/whoosh/qparser/default.py", line 355, in parse
    nodes = self.process(text, debug=debug)
  File "/home/nuklea/.virtualenvs/project/lib/python2.7/site-packages/whoosh/qparser/default.py", line 338, in process
    nodes = self.filterize(nodes, debug=debug)
  File "/home/nuklea/.virtualenvs/project/lib/python2.7/site-packages/whoosh/qparser/default.py", line 324, in filterize
    print_debug(debug, "..Result: %r" % nodes)
  File "/home/nuklea/.virtualenvs/project/lib/python2.7/site-packages/whoosh/qparser/syntax.py", line 63, in __repr__
    r += self.r()
  File "/home/nuklea/.virtualenvs/project/lib/python2.7/site-packages/whoosh/qparser/syntax.py", line 217, in r
    ", ".join(repr(n) for n in self.nodes))
  File "/home/nuklea/.virtualenvs/project/lib/python2.7/site-packages/whoosh/qparser/syntax.py", line 217, in <genexpr>
    ", ".join(repr(n) for n in self.nodes))
UnicodeEncodeError: 'ascii' codec can't encode characters in position 7-8: ordinal not in range(128)

Comments (4)

  1. Matt Chaput repo owner

    Changed FuzzyTermNode.r() to use %r instead of %s to avoid print decoding errors. Fixes issue #360.

    Also put if debug: lines on old debug prints in the query parser to avoid calling the repr methods on nodes unnecessarily.

    → <<cset 83676c93b942>>

  2. Log in to comment