2012-02-20 28 views
6

Tôi đang cố gắng sử dụng BeautifulSoup v4 để phân tích cú pháp tài liệu. Tôi gọi BeautifulSoup trên note.content, mà là một chuỗi trả về bởi API Evernote:Google App Engine Python 2.7 + lxml = Unicode ParserError

soup = BeautifulSoup(note.content)

tôi đã kích hoạt lxml trong tập tin app.yaml tôi:

libraries: 
- name: lxml 
    version: "2.3" 

Lưu ý rằng điều này hoạt động trên phát triển địa phương của tôi máy chủ. Tuy nhiên, khi triển khai tới đám mây của Google tôi nhận được lỗi sau:

Lỗi Trace:

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 

UPDATE:

Tôi đã kiểm tra ra parser.pxi, và tôi thấy những dòng mã mà đã tạo lỗi:

elif python.PyUnicode_Check(data): 
      if _UNICODE_ENCODING is NULL: 
       raise ParserError, \ 
        u"Unicode parsing is not supported on this platform" 

Tôi nghĩ rằng phải có điều gì đó về môi trường triển khai GAE gây ra lỗi này , nhưng tôi không chắc chắn những gì.

UPDATE 2:

Vì BeautifulSoup sẽ tự động rơi trở lại vào phân tích cú pháp khác, tôi đã kết thúc bỏ lxml từ ứng dụng của tôi hoàn toàn. Làm như vậy đã khắc phục được sự cố.

+0

Bạn có lỗi này bằng cách sử dụng SDK hoặc trong sản xuất? (hoặc cả hai). – proppy

+0

Chỉ trong sản xuất; Nó hoạt động tốt trên SDK với localhost. – zzz

+0

Tôi gặp vấn đề tương tự, và đã hạ cánh bằng cách xóa lxml. Tuy nhiên, khoan dung của html.parser của Python khá tệ và hầu hết các trang của tôi không được phân tích cú pháp vì điều này –

Trả lời

1

Cố gắng phân tích cú pháp chuỗi utf-8 thay vì unicode.

Các vấn đề liên quan