Confusing exception when non-markup passed into BeautifulSoup constructor
Bug #2071530 reported by
Thomas E Tresch
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Beautiful Soup |
Fix Committed
|
Undecided
|
Unassigned |
Bug Description
D:\tresc\
<bound method HTTPResponse.read of <http.client.
Traceback (most recent call last):
File "D:\tresc\
Scraper(
File "D:\tresc\
sp = BeautifulSoup(xml, parser)
File "D:\tresc\
elif len(markup) <= 256 and (
TypeError: object of type 'method' has no len()
To post a comment you must log in.
Thanks for taking the time to file this issue. Based on the first line of your program's output, you are passing a method (http.client. HTTPResponse. read) into the BeautifulSoup constructor as the `markup` argument. This won't work. The contract of the BeautifulSoup constructor is that `markup` can be "a string or an open filehandle." (https:/ /www.crummy. com/software/ BeautifulSoup/ bs4/doc/ #making- the-soup)
Calling the read() method would work (it returns a string), and passing in the HTTPResponse object would work (it acts like a filehandle), but passing in a method isn't supported.
For more information, see this Stack Overflow question: /stackoverflow. com/questions/ 57301959/ beautiful- soup-error- object- of-type- method- has-no- len
https:/
I'm leaving this issue open until I decide whether or not to make a change improving the error message in situations where `markup` doesn't fulfill the necessary contract.