gpt4 book ai didi

google-app-engine - Google App Engine Python 2.7 + lxml = Unicode ParserError

转载 作者:太空宇宙 更新时间:2023-11-03 15:23:15 24 4
gpt4 key购买 nike

我正在尝试使用 BeautifulSoup v4解析文档。我在 note.content 上调用 BeautifulSoup,它是 Evernote 的 API 返回的字符串:

soup = 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。这样做解决了问题。

最佳答案

尝试解析 utf-8 字符串而不是 unicode。

关于google-app-engine - Google App Engine Python 2.7 + lxml = Unicode ParserError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9362983/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com