Posts Tagged ‘_detectEncoding’

BeautifulSoup: _detectEncoding error

September 30, 2012 Leave a comment

While parsing an HTML page with BeautifulSoup, I got a similar error message:

File ".../", line 1915, in _detectEncoding
TypeError: expected string or buffer

In the code I had this:

text = get_page(url)
soup = BeautifulSoup(text)


text = get_page(url)
text = str(text)    # here is the trick
soup = BeautifulSoup(text)

Tip from here.

Categories: python Tags: ,