[Tutor] Simple example that won't work!

ak@silmarill.org ak@silmarill.org
Sat, 16 Jun 2001 21:56:00 -0400


On Sat, Jun 16, 2001 at 03:29:48PM -0400, Jay Parlar wrote:
> 
> 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.0 in the PythonWin environment.
> 
> Any help would be GREATLY appreciated,
> Jay P.

The problem is that there was a bug in python where it'd accept (host,port)
as an argument in some situation, and then it was fixed to accept ((host, port))- in other words, a tuple containing 2 elements instead of just two elements.
This pops up all the time when you're using code written for before 2.0 I think.
So, you can either fix that or use 1.5.2.

> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

-- 
Lime and limpid green
a second scene
A fight between the blue
you once knew
        - Syd