[Tutor] Can't make urllib do ftp

Andrei Kulakov ak@silmarill.org
Sun, 18 Nov 2001 21:11:46 -0500


On Sun, Nov 18, 2001 at 08:05:43PM -0600, Timothy Wilson wrote:
> Hi everyone,
> 
> I'm messing with the urllib module to retrieve the current weather
> conditions from our closest National Weather Service reporting station. The
> data is available at
> ftp://weather.noaa.gov/data/observations/metar/stations/KSGS.TXT
> 
> Unfortunately, I get the following error. This works perfectly when I do
> HTTP. The docs indicate that urllib should handle ftp just fine. Any ideas?
> 
> wilson@copland:~/python$ python2.1
> Python 2.1.1 (#1, Oct 20 2001, 16:44:06)
> [GCC 2.95.4 20011006 (Debian prerelease)] on linux2
> Type "copyright", "credits" or "license" for more information.
> >>> import urllib
> >>> url = "ftp://weather.noaa.gov/data/observations/metar/stations/KSGS.TXT"
> >>> f = urllib.urlopen(url)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
>   File "/usr/lib/python2.1/urllib.py", line 71, in urlopen
>     return _urlopener.open(url)
>   File "/usr/lib/python2.1/urllib.py", line 176, in open
>     return getattr(self, name)(url)
>   File "/usr/lib/python2.1/urllib.py", line 427, in open_ftp
>     host, path = splithost(url)
>   File "/usr/lib/python2.1/urllib.py", line 932, in splithost
>     match = _hostprog.match(url)
> TypeError: expected string or buffer
> >>>
> 
> -Tim

I used ftplib, and it works just fine (although it's a bit odd..).
> 
> --
> Tim Wilson      |   Visit Sibley online:   | Check out:
> Henry Sibley HS |  http://www.isd197.org   | http://www.zope.com
> W. St. Paul, MN |                          | http://slashdot.org
> wilson@visi.com |  <dtml-var pithy_quote>  | http://linux.com
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

-- 
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org