How to fix this AttributeError?
NickName:Zeynel Ask DateTime:2011-11-16T23:06:35

How to fix this AttributeError?

I installed a stripe package yesterday and now my app is not running. I am trying to understand where the problem is. Is it something to do with PyShell or HTLParser or something else. I am posting with GAE tag as well hoping that the trace from logs may give a clue about the problem:

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'

This is 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 was working fine until yesterday.

And these are my other questions:

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

Copyright Notice:Content Author:「Zeynel」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/8153823/how-to-fix-this-attributeerror

Answers
ekhumoro 2011-11-16T15:27:26

There are one or two issues with the code you posted (mainly to do with initializing the HTMLParser properly).\n\nTry running this amended version of your script:\n\nfrom HTMLParser import HTMLParser\n\nclass MLStripper(HTMLParser):\n def __init__(self):\n # initialize the base class\n HTMLParser.__init__(self)\n\n def read(self, data):\n # clear the current output before re-use\n self._lines = []\n # re-set the parser's state before re-use\n self.reset()\n self.feed(data)\n return ''.join(self._lines)\n\n def handle_data(self, d):\n self._lines.append(d)\n\ndef strip_tags(html):\n s = MLStripper()\n return s.read(html)\n\nhtml = \"\"\"Python's <code>easy_install</code>\n makes installing new packages extremely convenient.\n However, as far as I can tell, it doesn't implement\n the other common features of a dependency manager -\n listing and removing installed packages.\"\"\"\n\nprint strip_tags(html)\n",


Grant Curell 2016-05-24T02:20:10

This error also appears if you override the reset method in HTMLParser class.\n\nIn my case I had added a method named reset for some other functionality and discovered that while Python does not tell you there is a problem with doing this (nor was there any indication I was overriding anything), it breaks the HTMLParser class.",


SoSen 2019-07-12T11:08:33

You need to call the init in superclass HTMLParser.\n\nyou can also do it by using\n\nclass MLStripper(HTMLParser):\n def __init__(self):\n super(MLStripper, self).__init__()\n set()\n self.fed = []\n",


More about “How to fix this AttributeError?” related questions

How to fix this AttributeError?

I installed a stripe package yesterday and now my app is not running. I am trying to understand where the problem is. Is it something to do with PyShell or HTLParser or something else. I am posting...

Show Detail

How to fix PyAutoGUI AttributeError

I Have been trying to get PyAutoGUI to click one of the applications at the bottom of my screen using a very simple code. However, whenever I try to run this code I get an error that I believe is ...

Show Detail

how to fix AttributeError

I'm making a web wrapper with python. but i can't fix the error AttributeError: 'NoneType' object has no attribute 'find' this is my code def extract_indeed_jobs(last_page): jobs = [] # for

Show Detail

How to fix Python Enum - AttributeError(name) from None error?

Trying to use an enum in Python 3.7.3, getting the following error. Already tried to install - and uninstall - enum34, but it still does not work. Did all the operations in a virtual environment (a...

Show Detail

How to fix Python Enum - AttributeError(name) from None error?

Trying to use an enum in Python 3.7.3, getting the following error. Already tried to install - and uninstall - enum34, but it still does not work. Did all the operations in a virtual environment (a...

Show Detail

How to fix this AttributeError

I am trying to access a variable within a function in a class and print it. Whenever I try I keep getting the error: AttributeError: 'NoneType' object has no attribute 'job_ID'. def driver(): ...

Show Detail

How to fix an AttributeError in django?

I am trying to return the list of playlists that are associated with the current logged in user and I get an error saying: AttributeError: 'QuerySet' object has no attribute 'has_header I have incl...

Show Detail

How to fix this "AttributeError" in python?

I've googled my error message "AttributeError: 'NoneType' object has no attribute 'text'", but I still can't find out how to fix this error. Please help! # -*- coding: UTF-8 -*- import io import s..

Show Detail

How to fix a AttributeError in Python?

I don't success to fix this error on my code. Python wrote me this error message: "Traceback (most recent call last): File "C:\Users\Chloé CHAUMETON\Documents\BioAxial\1_R&amp;D\4_Software\2_Pyt...

Show Detail

How to fix AttributeError when using barplot in python?

I'm trying to get a barplot out of some data in python through using the library seaborn. My data looks something like this: data_list = [[value_1, value_2, value_3, value_4], [1, 2, 3, 4]] I'm now

Show Detail