Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python error when using urllib.open

Tags:

python

urllib

When I run this:

import urllib

feed = urllib.urlopen("http://www.yahoo.com")

print feed

I get this output in the interactive window (PythonWin):

<addinfourl at 48213968 whose fp = <socket._fileobject object at 0x02E14070>>

I'm expecting to get the source of the above URL. I know this has worked on other computers (like the ones at school) but this is on my laptop and I'm not sure what the problem is here. Also, I don't understand this error at all. What does it mean? Addinfourl? fp? Please help.

like image 792
Alan Avatar asked Sep 11 '25 06:09

Alan


2 Answers

Try this:

print feed.read()

See Python docs here.

like image 166
RexE Avatar answered Sep 12 '25 19:09

RexE


urllib.urlopen actually returns a file-like object so to retrieve the contents you will need to use:

import urllib

feed = urllib.urlopen("http://www.yahoo.com")

print feed.read()
like image 41
Wayne Koorts Avatar answered Sep 12 '25 19:09

Wayne Koorts