間違った機能を使ったようです。-で.fromstring
-エラーメッセージはありません
xml_ = load() # here comes the unicode string with Cyrillic letters
print xml_ # prints everything fine
print type(xml_) # 'lxml.etree._ElementUnicodeResult' = unicode
xml = xml_.decode('utf-8') # here is an error
doc = lxml.etree.parse(xml) # if I do not decode it - the same error appears here
File "testLog.py", line 48, in <module>
xml = xml_.decode('utf-8')
File "/usr/lib/python2.7/encodings/utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 89-96: ordinal not in range(128)
もしも
xml = xml_.encode('utf-8')
doc = lxml.etree.parse(xml) # here's an error
また
xml = xml_
それから
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 89: ordinal not in range(128)
私がそれを正しく理解している場合:非ASCII文字列を内部表現にデコードしてから、この表現を操作して、出力に送信する前にエンコードし直す必要がありますか?私はまさにこれをしているようです。
'Accept-Charset': 'utf-8'
ヘッダーがあるため、入力データはunt-8である必要があります。