BeautifulSoup cannot concatenate str and NoneType objects

Hi, I am running python 2.7.1 and beautifulsoup 3.2.0 if I try to load some XML feed using

ifile = open(os.path.join(self.path,str(self.FEED_ID)+'.xml'), 'r') file_data = BeautifulStoneSoup(ifile, convertEntities=BeautifulStoneSoup.XHTML_ENTITIES) 

im gets the following error

  File "C:\dev\Python27\lib\site-packages\BeautifulSoup.py", line 1144, in __ini t__ self._feed(isHTML=isHTML) File "C:\dev\Python27\lib\site-packages\BeautifulSoup.py", line 1186, in _feed SGMLParser.feed(self, markup) File "C:\dev\Python27\lib\sgmllib.py", line 103, in feed self.rawdata = self.rawdata + data TypeError: cannot concatenate 'str' and 'NoneType' objects 

I try to look everywhere, but without success ... please advise

+4
source share
2 answers

In the example ...

 from BeautifulSoup import BeautifulStoneSoup xml = "<doc><tag1>Contents 1<tag2>Contents 2<tag1>Contents 3" soup = BeautifulStoneSoup(xml) print soup.prettify() (...) 

from here . I suppose you need to pass the string as the first parameter instead of the ifile file object, try:

 file_data = BeautifulStoneSoup(ifile.read(), convertEntities=BeautifulStoneSoup.XHTML_ENTITIES) 
0
source

I also had this error. This worked for me:

 from unidecode import unidecode file_data = BeautifulSoup(unidecode(ifile.read())) 
0
source

All Articles