运行空字符串我的Python 2.7.8在CentOS 6.8在我的服务器时的Apache2 + WSGI建。我的应用程序应该使用http POST处理收到的日期,然后根据从本地.xml文件获取的XML模板创建指令。最后,它必须以200 OK响应发送xml指令。应用程序的逻辑似乎工作正常,我可以看到我更新的XML树:Python的LXML etree.tostring()返回在mod_wsgi的
print etree.tostring(root, pretty_print=True, xml_declaration-True, encoding='UTF-8')
的问题出现在我的代码,我正在做同样的操作下一行要发生的,但试图分配输出变量:
xml_body = etree.tostring(root, pretty_print=True, xml_declaration-True, encoding='UTF-8')
打印xml_body
输出为空字符串,这样我的应用程序,然后返回一无所获到Apache。
我的环境信息可能会有所帮助:
==For bug report ===
Python : sys.version_info(major=2, minor=7, micro=8, releaselevel='final', serial=0)
lxml.etree : (3, 6, 4, 0)
libxml used : (2, 7, 6)
libxml compiled : (2, 9, 4)
libxslt used : (1, 1, 26)
libxslt compiled : (1, 1, 29)
它类似于这样bug report然而,笔者提到的它并没有在所有的工作。还有一个request其中包含类似的问题,但它仍然没有解决。 我已经签出我可能会成功地在Python CLI播放相同的场景:
Python 2.7.8 (default, May 15 2016, 12:46:09)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from lxml import etree
>>> foo = etree.Element('foo')
>>> foo
<Element foo at 0x7f5097c4fc20>
>>> foo.tag
'foo'
>>> foo.text = 'barrisimo'
>>> xmlb = etree.tostring(foo, pretty_print=True, xml_declaration=True, encoding='UTF-8')
>>> print xmlb
<?xml version='1.0' encoding='UTF-8'?>
<foo>barrisimo</foo>1
曾有人遇到过同样的问题?我在死路一条,我会很感激任何帮助,想法或有用的链接。
似乎在'mod_wsgi'中'tostring()'有问题,仍然没有解决方案。 – furas
你能修复你的代码片断吗?这甚至不是有效的Python。你不能像在''xml_body = print etree.tostring(...)''中那样将'print''的结果赋值给一个变量。 –
您是否注意到链接帖子中的建议,其中讨论了使用旧版本的libxml和libxslt而不是最初编译的lxml?你的情况似乎完全匹配,并提到,可能会导致问题。你确定你升级了这些库的系统包吗? –