2011-11-16 16 views
9

어제 스트라이프 패키지를 설치했는데 이제 앱이 실행되고 있지 않습니다. 문제가 어디 있는지 이해하려고합니다. PyShell 또는 HTLParser 또는 다른 것과 관련이 있습니다. 나는 GAE 태그뿐만 아니라 로그에서 추적이 문제에 대해 단서를 얻을 수 있다는 기대와 함께 게시하고있다 :이 AttributeError 문제를 해결하는 방법?

MLStripper instance has no attribute 'rawdata' 
Traceback (most recent call last): 
    File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/_webapp25.py", line 703, in __call__ 
    handler.post(*groups) 
    File "/base/data/home/apps/ting-1/1.354723388329082800/ting.py", line 2070, in post 
    pitch_no_tags = strip_tags(pitch_original) 
    File "/base/data/home/apps/ting-1/1.354723388329082800/ting.py", line 128, in strip_tags 
    s.feed(html) 
    File "/base/python_runtime/python_dist/lib/python2.5/HTMLParser.py", line 107, in feed 
    self.rawdata = self.rawdata + data 
AttributeError: MLStripper instance has no attribute 'rawdata' 

이 MLStripper입니다 : MLStripper 어제까지 잘 작동했다

from HTMLParser import HTMLParser 

class MLStripper(HTMLParser): 
    def __init__(self): 
     set() 
     self.fed = [] 
    def handle_data(self, d): 
     self.fed.append(d) 
    def get_data(self): 
     return ''.join(self.fed) 

def strip_tags(html): 
    s = MLStripper() 
    s.feed(html) 
    return s.get_data() 

.

당신이 게시 된 코드를 하나 또는 두 가지 문제가 있습니다

https://stackoverflow.com/questions/8152141/how-to-fix-this-attributeerror-with-htmlparser-py

https://stackoverflow.com/questions/8153300/how-to-fix-a-corrupted-pyshell-py

답변

21

(주로 제대로 HTMLParser를 초기화 함께 할 수있는) :

그리고 이들은 내 다른 질문입니다.

는 스크립트의 수정 된 버전을 실행 해보십시오 : 당신이 HTMLParser 클래스의 초기화 메소드를 오버라이드 (override)하는 경우

from HTMLParser import HTMLParser 

class MLStripper(HTMLParser): 
    def __init__(self): 
     # initialize the base class 
     HTMLParser.__init__(self) 

    def read(self, data): 
     # clear the current output before re-use 
     self._lines = [] 
     # re-set the parser's state before re-use 
     self.reset() 
     self.feed(data) 
     return ''.join(self._lines) 

    def handle_data(self, d): 
     self._lines.append(d) 

def strip_tags(html): 
    s = MLStripper() 
    return s.read(html) 

html = """Python's <code>easy_install</code> 
makes installing new packages extremely convenient. 
However, as far as I can tell, it doesn't implement 
the other common features of a dependency manager - 
listing and removing installed packages.""" 

print strip_tags(html) 
+0

답변에 많은 감사드립니다. 그것은 위대한 작품. 내가 이해할 수 있도록 코드에 몇 가지 코멘트를 추가 하시겠습니까? 그리고 왜 이것이 지금까지 몇 달 동안 제대로 작동하지 않았다고 생각하니 갑자기 작동을 멈췄습니다. 다시 한번 감사드립니다. – Zeynel

+1

@Zeynel. 원본 스크립트의 주요 변경 사항을 보여주기 위해 몇 가지 설명을 추가했습니다. 이전 스크립트가 작동하지 않는 이유는 시스템에서 최근에 변경된 내용을 모른 채로 말하기가 매우 어렵습니다. 그러나 어쨌든 수정 된 스크립트가 더 일반적이라고 생각합니다. – ekhumoro

+0

좋습니다. 다시 한번 감사드립니다. – Zeynel

1

에도이 오류가 나타납니다.

제 경우에는 다른 기능을 위해 reset이라는 이름의 메소드를 추가했으며 파이썬이이 일을하는 데 문제가 있다는 것을 알지 못했지만 (아무 것도 표시하지 않고 아무 것도 덮어 쓰지 않음), HTMLParser를 깨뜨린 것을 발견했습니다 수업.

관련 문제