【发布时间】:2012-03-10 21:40:21
【问题描述】:
我正在尝试使用BeautifulSoup v4 来解析文档。我在 note.content 上调用 BeautifulSoup,这是 Evernote 的 API 返回的字符串:
汤 = BeautifulSoup(note.content)
我在 app.yaml 文件中启用了 lxml:
libraries:
- name: lxml
version: "2.3"
请注意,这适用于我的本地开发服务器。但是,当部署到 Google 的云时,我收到以下错误:
错误跟踪:
Unicode parsing is not supported on this platform
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~ever-blog/1.356951374446096208/controller/blog.py", line 101, in get
soup = BeautifulSoup(note.content)
File "/base/data/home/apps/s~ever-blog/1.356951374446096208/lib/bs4/__init__.py", line 168, in __init__
self._feed()
File "/base/data/home/apps/s~ever-blog/1.356951374446096208/lib/bs4/__init__.py", line 181, in _feed
self.builder.feed(self.markup)
File "/base/data/home/apps/s~ever-blog/1.356951374446096208/lib/bs4/builder/_lxml.py", line 62, in feed
self.parser.feed(markup)
File "parser.pxi", line 1077, in lxml.etree._FeedParser.feed (third_party/apphosting/python/lxml/src/lxml/lxml.etree.c:76196)
ParserError: Unicode parsing is not supported on this platform
更新:
我检查了 parser.pxi,我发现这些代码行产生了错误:
elif python.PyUnicode_Check(data):
if _UNICODE_ENCODING is NULL:
raise ParserError, \
u"Unicode parsing is not supported on this platform"
我认为GAE的部署环境一定有什么导致这个错误,但我不确定是什么。
更新 2:
因为 BeautifulSoup 会自动依赖其他解析器,所以我最终从我的应用程序中完全删除了 lxml。这样做可以解决问题。
【问题讨论】:
-
您在使用 SDK 或在生产环境中是否有此错误? (或两者)。
-
仅在生产中;它在带有 localhost 的 SDK 上运行良好。
-
我有同样的问题,并通过删除 lxml 登陆。但是,Python 的 html.parser 的宽大处理非常糟糕,因此我的大部分页面都没有被解析
标签: google-app-engine unicode lxml python-2.7