ValueError: unknown url type
17,877
Solution 1
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
Solution 2
You need to pass a full URL: ie it must begin with http://
.
Solution 3
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>>
Author by
Jamus
Updated on June 04, 2022Comments
-
Jamus almost 2 years
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?