2011-11-16 23 views
9

Zainstalowałem wczoraj pakiet z paskiem, a teraz moja aplikacja nie działa. Próbuję zrozumieć, gdzie jest problem. Czy to ma coś wspólnego z PyShell lub HTLParser lub czymś innym. Jestem delegowania z tag GAE również nadzieję, że ślad z bali może dać pojęcia o problemie:Jak naprawić ten 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' 

To 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() 

MLStripper działa dobrze aż do wczoraj.

A oto inne moje pytania:

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

Odpowiedz

21

Istnieje jeden lub dwa problemy z kodem ty pisał (głównie do zrobienia z inicjowania HTMLParser prawidłowo).

Spróbuj uruchomić tę zmienioną wersję skryptu:

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

Wielkie dzięki za odpowiedź. Działa świetnie. Czy chcesz dodać kilka komentarzy do kodu, aby je zrozumieć? A także dlaczego myślisz, że to działało do tej pory od miesięcy i nagle przestało działać. Dzięki jeszcze raz. – Zeynel

+1

@Zeynel. Dodałem kilka komentarzy, aby pokazać główne zmiany wprowadzone w oryginalnym skrypcie. Dlaczego poprzedni skrypt przestał działać: trudno to powiedzieć, nie wiedząc, co ostatnio zmieniło się w twoim systemie. Ale w każdym razie myślę, że poprawiony scenariusz jest bardziej ogólnie poprawny. – ekhumoro

+0

Świetnie. Dzięki jeszcze raz. – Zeynel

1

Błąd ten pojawia się również wtedy przesłonić metodę resetowania w klasie HTMLParser.

W moim przypadku dodałem metodę o nazwie reset dla jakiejś innej funkcjonalności i odkryłem, że podczas gdy Python nie mówi o tym problemie (ani nie było żadnego wskazania, że ​​nadpisałem cokolwiek), zepsuje HTMLParser klasa.

Powiązane problemy