Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ValueError: unknown url type

The title pretty much says it all. Here's my code:

from urllib2 import urlopen as getpage
print = getpage("www.radioreference.com/apps/audio/?ctid=5586")

and here's the traceback error I get:

Traceback (most recent call last):
  File "C:/Users/**/Dropbox/Dev/ComServ/citetest.py", line 2, in <module>
    contents = getpage("www.radioreference.com/apps/audio/?ctid=5586")
  File "C:\Python25\lib\urllib2.py", line 121, in urlopen
    return _opener.open(url, data)
  File "C:\Python25\lib\urllib2.py", line 366, in open
    protocol = req.get_type()
  File "C:\Python25\lib\urllib2.py", line 241, in get_type
    raise ValueError, "unknown url type: %s" % self.__original
ValueError: unknown url type: www.radioreference.com/apps/audio/?ctid=5586

My best guess is that urllib can't retrieve data from untidy php URLs. if this is the case, is there a work around? If not, what am I doing wrong?

like image 367
Jamus Avatar asked Nov 30 '12 08:11

Jamus


3 Answers

You should first try to add 'http://' in front of the url. Also, do not store the results in print, as it is binding the reference to another (non callable) object.

So this line should be:

page_contents = getpage("http://www.radioreference.com/apps/audio/?ctid=5586")

This returns a file like object. To read its contents you need to use different file manipulation methods, like this:

for line in page_contents.readlines():
    print line
like image 168
NlightNFotis Avatar answered Oct 20 '22 19:10

NlightNFotis


You need to pass a full URL: ie it must begin with http://.

like image 3
Daniel Roseman Avatar answered Oct 20 '22 18:10

Daniel Roseman


Simply use http://www.radioreference.com/apps/audio/?ctid=5586 and it'll work fine.

In [24]: from urllib2 import urlopen as getpage

In [26]: print getpage("http://www.radioreference.com/apps/audio/?ctid=5586")
<addinfourl at 173987116 whose fp = <socket._fileobject object at 0xa5eb6ac>>
like image 2
Ashwini Chaudhary Avatar answered Oct 20 '22 20:10

Ashwini Chaudhary