Simple example that won't work!

Jay Parlar jparlar at home.com
Mon Jun 18 22:49:51 EDT 2001


I posted this to the Python Tutor list, but wasn't really satisfied with my result. I'll just repaste it here, and hope for better luck 
;-)  I've been told that this list can be quite astounding, so let's see what happens :)



Hello to all my fellow Python lovers. I'm only learning Python right now (after a few years working with the comparatively 
terrible C/C++) and I am absolutely loving it. To learn the language, I am using Wesley Chun's "Core Python Programming". 
It's a very good book with some really good examples, but it's with one of the examples that I'm having difficulty. 

The example is a simple web-based example. All it does is retrieve an HTML document, and print out the first and last non-
blank lines of the page. The error, though, occurs with the urlretrieve( ) call. When I call it, I get the following exception 
message:

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(): 

My exact call was

retval = urlretrieve(url)[0], where url is any web address.

Now, the interesting thing is the code works fine on another computer it's been tried on, but no luck on mine. I'm running 
Win95b, with Python2.1 in the PythonWin environment.

Any help would be GREATLY appreciated,
Jay P.






More information about the Python-list mailing list