生产中的lxml编码错误 [英] lxml encoding errors on production

查看:126
本文介绍了生产中的lxml编码错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用lxml处理一些数据.它可以在我的开发服务器上正常工作,但在生产中可以使用以下代码:

I am trying to process some data with lxml. It works fine on my development server, but on production the following code:

parser = etree.XMLParser(encoding='cp1251')

抛出:

  File "parser.pxi", line 1288, in lxml.etree.XMLParser.__init__ (third_party/apphosting/python/lxml/src/lxml/lxml.etree.c:77726)
  File "parser.pxi", line 738, in lxml.etree._BaseParser.__init__ (third_party/apphosting/python/lxml/src/lxml/lxml.etree.c:73404)
LookupError: unknown encoding: 'cp1251'

我正在使用lxml 2.3. GAE似乎支持相同的版本.那么为什么会出现这个错误呢?

I am using lxml 2.3. The same version seems to be supported by GAE. So why is this error?

修改:

我为XMLParser指定了不同的编码,例如cp1252,ISO-8859-5,ISO-8859-2,并且它在GAE上始终会引发相同的错误,但可以在我的本地计算机上使用.这些是流行的编码,GAE上的lxml必须支持它们.我相信基于GAE的lxml出现了问题.

I specified different encodings to XMLParser, such as cp1252, ISO-8859-5, ISO-8859-2 and it always throwed the same error on GAE, but works on my local machine. These are popular encodings and lxml on GAE must support them. I believe this is something wrong with lxml build on GAE.

我创建了一个问题: http://code.google.com /p/googleappengine/issues/detail?id = 7315

Edit2 :

完整追溯:

unknown encoding: 'cp1251'
Traceback (most recent call last):
  File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1511, in __call__
    rv = self.handle_exception(request, response, e)
  File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1505, in __call__
    rv = self.router.dispatch(request, response)
  File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1253, in default_dispatcher
    return route.handler_adapter(request, response)
  File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1077, in __call__
    return handler.dispatch()
  File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 547, in dispatch
    return self.handle_exception(e, self.app.debug)
  File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 545, in dispatch
    return method(*args, **kwargs)
  File "/base/data/home/apps/s~my_cool_app_id/1.358126884781269352/main.py", line 29, in get
    parser = etree.XMLParser(encoding='cp1251')
  File "parser.pxi", line 1288, in lxml.etree.XMLParser.__init__ (third_party/apphosting/python/lxml/src/lxml/lxml.etree.c:77726)
  File "parser.pxi", line 738, in lxml.etree._BaseParser.__init__ (third_party/apphosting/python/lxml/src/lxml/lxml.etree.c:73404)
LookupError: unknown encoding: 'cp1251'

推荐答案

在OS X上,此行为似乎已打开一个错误,其中指定encoding ="cp1252"导致上述错误.注释还指定了其他受影响的系统: https://bugs.launchpad.net/lxml/+ bug/707396

There seems to be a bug open about this behavior on OS X where specifying encoding="cp1252" resulted in the error above. The comments also specify other systems as affected: https://bugs.launchpad.net/lxml/+bug/707396

您是否尝试过指定其他编码类型? (以查看cp1252是否只是一个问题)

Have you tried specifying other encoding types? (to see if it's just a problem with cp1252)

这篇关于生产中的lxml编码错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆