Skip to content Skip to sidebar Skip to footer

Attributeerror: 'httpresponse' Object Has No Attribute 'type'

So, I am trying to build a program that will retrieve the scores of the NHL's season through the use of yahoo's RSS feed. I am not an experienced programmer, so some things haven't

Solution 1:

The problem is that you're trying to call urlopen on the result of urlopen.

Just call it once, like this:

nhl_site = urlopen('http://sports.yahoo.com/nhl/rss')
tree = ET.parse(nhl_site)

The error message probably could be nicer. If you look at the docs for urlopen:

Open the URL url, which can be either a string or a Request object.

Clearly the http.client.HTTPResponse object that it returns is neither a string nor a Request object. What's happened here is that urlopen sees that it's not a string, and therefore assumes it's a Request, and starts trying to access methods and attributes that Request objects have. This kind of design is generally a good thing, because it lets you pass things that act just like a Request and they'll just work… but it does mean that if you pass something that doesn't act like a Request, the error message can be mystifying.

Post a Comment for "Attributeerror: 'httpresponse' Object Has No Attribute 'type'"