Python BeautifulSoup无法连接str和非类型对象

Python BeautifulSoup无法连接str和非类型对象,python,beautifulsoup,Python,Beautifulsoup,您好,我正在运行python 2.7.1和beautifulsoup 3.2.0 如果我尝试使用 ifile = open(os.path.join(self.path,str(self.FEED_ID)+'.xml'), 'r') file_data = BeautifulStoneSoup(ifile, convertEntities=BeautifulStoneSoup.XHTML_ENTITIES) 我得到以下错误 File "C:\dev\Python27\lib\si

您好,我正在运行python 2.7.1和beautifulsoup 3.2.0 如果我尝试使用

ifile = open(os.path.join(self.path,str(self.FEED_ID)+'.xml'), 'r')
file_data = BeautifulStoneSoup(ifile, 
    convertEntities=BeautifulStoneSoup.XHTML_ENTITIES)
我得到以下错误

  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
我试着到处找,但没有成功。。。请用这个例子告诉我

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

我也有这个错误。这对我很有用:

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

我尝试过这一点,但没有效果,只有当我使用unicode(ifile.read(),'utf-8',errors='ignore')而不是ifile时,它才起作用……它被修复了。不是吗?您需要的是.read()+unicode。我说的对吗?没有。read()没有帮助,我必须使用unicore errors=ignore。。。从我的观点来看,whitch是错误的,而且我必须在本例中使用utf-8编码,但是如果我使用其他编码呢?这是错误的。。。这个问题首先应该解决,而不仅仅是解决“BeautifulSoup不能连接str和NoneType对象”,Guido van Rossum也不能,他发明了python@米凯罗比:是的,但他们可以采取措施防止这种情况发生。。。
from unidecode import unidecode
file_data = BeautifulSoup(unidecode(ifile.read()))