ValueError: unknown url type
Asked Answered
G

3

6

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?

Gause answered 30/11, 2012 at 8:54 Comment(0)
S
10

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
Sibby answered 30/11, 2012 at 8:57 Comment(2)
Thank you. Not only did you answer my question, you answered my next! ;)Gause
I have the same error and I have downloaded the website with wget, how can I open that?Barahona
D
3

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

Doley answered 30/11, 2012 at 8:56 Comment(0)
F
2

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>>
Feaze answered 30/11, 2012 at 8:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.