简体   繁体   中英

python wsgi pymorphy2 error iternal

trying to return value of pymorphy2 using apache with wsgi module & getting error 500 log says TypeError: sequence of byte string values expected, value of type Parse found

i dont know what to do! in Python im rookie

my python code is

import pymorphy2
import cgi

morph = pymorphy2.MorphAnalyzer()
morphid = morph.parse(u'конь')

def app(environ, start_response):
    words = morphid

    start_response('200 OK', [('Content-Type', 'text/html')])
    return [words]

but in shell it works... :(
please help i dont understand what is form or type of var words need to me.

or may be that is all wrong

in shell result is

morph = pymorphy2.MorphAnalyzer()

words = morph.parse(u'конь')

print "words"

[Parse(word=u'\xf1\xf2\xe0\xeb\xe8', tag=OpencorporaTag('LATN'), normal_form=u'\xf1\xf2\xe0\xeb\xe8', score=1.0, methods_stack=((<LatinAnalyzer>, u'\xf1\xf2\xe0\xeb\xe8'),))]

Thanks to everyone!

As you can see, you need to return sequence of byte string but you are returning word which is of type Parse . if you want the response to be exactly the same as the thing you get from the console, try

words = str(morphid[0]).encode()

It will return the string of the result which is encoded() thus can be used as a response.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM