[Tutor] Can't make urllib do ftp

Timothy Wilson wilson@visi.com
Sun, 18 Nov 2001 20:05:43 -0600 (CST)


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

--
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