[英]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尝试使用带有 wsgi 模块的 apache 返回 pymorphy2 的值并得到错误 500 日志说 TypeError: 预期的字节字符串值序列,已找到类型解析的值
i dont know what to do!我不知道该怎么办! in Python im rookie在 Python 中我是菜鸟
my python code is我的python代码是
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... :(但在 shell 中它有效...... :(
please help i dont understand what is form or type of var words need to me.请帮助我不明白什么是我需要的 var 词的形式或类型。
or may be that is all wrong或者可能这都是错的
in shell result is在外壳结果是
morph = pymorphy2.MorphAnalyzer()变形 = pymorphy2.MorphAnalyzer()
words = morph.parse(u'конь') 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
.如您所见,您需要返回字节字符串序列,但您返回的是Parse
类型的 word 。 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.它将返回encoded()
的结果字符串,因此可以用作响应。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.