Simple example that won't work!
Jay Parlar
jparlar at home.com
Tue Jun 19 10:42:13 EDT 2001
>
>> My exact call was
>> retval = urlretrieve(url)[0], where url is any web address.
>
>Some more code would be appreciated, so we don't have to spend time to
>guess anything.
>
>
>--
>Rikard Bosnjakovic - http://bos.hack.org/cv/ - ICQ: 1158217
>
>Anyone sending unwanted advertising e-mail to my address will be
>charged $250 for network traffic and computing time. By extracting my
>address from this message or its header, you agree to these terms.
>--
>http://mail.python.org/mailman/listinfo/python-list
>
Well, I didn't include anymore code because it was really trivial, and I thought the problem could be found from the
exceptions. However, since you asked, I'll paste the code in as well.
from urllib import urlretrieve
from string import strip
def firstnonblank(lines):
for eachLine in lines:
if strip(eachLine) =='':
continue
else:
return eachLine
def firstlast(webpage):
f = open(webpage)
lines = f.readlines()
f.close()
print firstnonblank(lines),
lines.reverse()
print firstnonblank(lines),
def download(url = 'http://www.opera.com:3600',process = firstlast):
print url
retval= urlretrieve(url)[0]
if retval:
process(retval)
def urlEntry():
url2 = raw_input('Please enter the URL')
download(url2,firstlast)
if __name__ == '__main__':
download()
The error, as stated before, occurs on the call to urlretrieve(), and the exception is as follows:
Traceback (most recent call last):
File "C:\Program Files\Python20\Pythonwin\pywin\framework\scriptutils.py", line 301, in RunScript
exec codeObject in __main__.__dict__
File "C:\Program Files\Python20\scripts\grabweb.py", line 37, in ?
download()
File "C:\Program Files\Python20\scripts\grabweb.py", line 23, in download
retval= urlretrieve(url)[0]
File "C:\PROGRA~1\PYTHON20\LIB\urllib.py", line 68, in urlretrieve
return _urlopener.retrieve(url, filename, reporthook, data)
File "C:\PROGRA~1\PYTHON20\LIB\urllib.py", line 198, in retrieve
fp = self.open(url, data)
File "C:\PROGRA~1\PYTHON20\LIB\urllib.py", line 166, in open
return getattr(self, name)(url)
File "C:\PROGRA~1\PYTHON20\LIB\urllib.py", line 267, in open_http
h = httplib.HTTP(host)
File "c:\program files\python20\lib\httplib.py", line 640, in __init__
self._conn = self._connection_class(host, port)
File "c:\program files\python20\lib\httplib.py", line 330, in __init__
self._set_hostport(host, port)
File "c:\program files\python20\lib\httplib.py", line 336, in _set_hostport
port = int(host[i+1:])
ValueError: invalid literal for int():
Hopefully this is enough information now, and thank you to anyone who's looking at this.
Jay P.
More information about the Python-list
mailing list