Reputation: 139
I've been facing the problem where I have an XML file with Unicode strings and need to evaluate an Xpath on it, through lxml in Python-2.7.
# -*- coding: utf-8 -*-
from lxml import etree
...
class Language:
description = None
def __init__(self, description):
xpath = "//language[./description = '{}']//description/text()".format(description)
self.description= lang_xml.xpath(xpath)
...
lang = Language(u"Norwegian Bokmål")
Gives error: UnicodeEncodeError: 'ascii' codec can't encode character u'\xe5' in position 14: ordinal not in range(128)
Upvotes: 0
Views: 244
Reputation: 798746
Stop mixing them.
xpath = u"//language[./description = '{}']//description/text()".format(description)
Upvotes: 1