[Tutor] need help with urllib

Andrew Andrew <angelopoulos@csi.com>
Sat, 5 Oct 2002 13:31:55 -0400


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Jmllr891,

   New to python myself, been lurking here the past week... tried
what
   you tried without a problem from idle. The only difference I see
is
   that I explicitly list the file I wanted and gave it a new local
   name.

   import urllib
   loc = urllib.URLopener()
   loc.retrieve("http://i.dslr.net/avatars/418397.gif", "junk.gif")
   ('junk.gif', <mimetools.Message instance at 0x00F144B0>)

   It created the .gif without a problem in my python dir.

   When I tried it without the filename I got this:
   Traceback (most recent call last):
   File "<pyshell#14>", line 1, in ?
   lox.retrieve("http://i.dslr.net/avatars/", "418397.gif")
   File "D:\PYTHON22\lib\urllib.py", line 210, in retrieve
   fp = self.open(url, data)
   File "D:\PYTHON22\lib\urllib.py", line 178, in open
   return getattr(self, name)(url)
   File "D:\PYTHON22\lib\urllib.py", line 301, in open_http
   return self.http_error(url, fp, errcode, errmsg, headers)
   File "D:\PYTHON22\lib\urllib.py", line 318, in http_error
   return self.http_error_default(url, fp, errcode, errmsg, headers)
   File "D:\PYTHON22\lib\urllib.py", line 324, in http_error_default
   raise IOError, ('http error', errcode, errmsg, headers)
   IOError: ('http error', 404, 'Not Found', <mimetools.Message
instance at 0x01269F10>)

   You catching the exception and maybe doing something with it?

   (btw, me: Python 2.2, Win98 SE, Netscape7)

- -- Andrew
mailto:angelopoulos@csi.com


- --
Saturday, October 5, 2002, 12:43:00 PM, you wrote:


Jcc> I've recently been trying to write a script that will download
images off the
Jcc> web for me (say a daily comic strip or something of that sort).

Jcc> The script works perfectly fine, it downloads the image and
produces no
Jcc> errors. But the image is always corrupt or something. No matter
what I try to
Jcc> view it in (even a web browser) it can't be displayed.

Jcc> This is my code (this one downloads the Python logo):
Jcc> ---------------------------------
Jcc> import urllib

Jcc> image = URLopener()
Jcc> image.retrieve('http://www.python.org/pics/', 'pythonHi.gif')
Jcc> ---------------------------------

Jcc> What could be wrong? My internet connection maybe?

-----BEGIN PGP SIGNATURE-----
Version: PGP 6.5i
Comment: It isn't so strange. You put your mail in envelopes, no?

iQA/AwUBPZ8iE8SLfgHZWt7tEQL09QCgi1mu7kEj/3l7ODulTOTrn8Ys3NIAoMVy
z+K6zRPTSbJRGuYBmUvFQfl+
=cmYF
-----END PGP SIGNATURE-----