urlopen() problem/bug?

Hermann Himmelbauer h9025909 at speth13.wu-wien.ac.at
Mon May 14 05:03:20 EDT 2001


Hi,
I wrote the following little python code to retieve a page from
http://www.sms.at (other websites work):

#!/usr/bin/env python
from urllib import *
tfd=urlopen('http://www.sms.at',None) 

If I execute this program WITHOUT being behind a proxy, there is an
endless loop that starts like this:

----- snip --------
Traceback (most recent call last):
  File "./testsmsat.py", line 5, in ?
    tfd=urlopen('http://www.sms.at',None)
  File "/scratch1/dusty/python/lib/python2.0/urllib.py", line 61, in
urlopen
    return _urlopener.open(url)
  File "/scratch1/dusty/python/lib/python2.0/urllib.py", line 166, in
open
    return getattr(self, name)(url)
  File "/scratch1/dusty/python/lib/python2.0/urllib.py", line 286, in
open_http
    return self.http_error(url, fp, errcode, errmsg, headers)
  File "/scratch1/dusty/python/lib/python2.0/urllib.py", line 299, in
http_error
    result = method(url, fp, errcode, errmsg, headers)
  File "/scratch1/dusty/python/lib/python2.0/urllib.py", line 534, in
http_error_302
    return self.open(newurl)
  File "/scratch1/dusty/python/lib/python2.0/urllib.py", line 166, in
open
    return getattr(self, name)(url)
  File "/scratch1/dusty/python/lib/python2.0/urllib.py", line 286, in
open_http
    return self.http_error(url, fp, errcode, errmsg, headers)
  File "/scratch1/dusty/python/lib/python2.0/urllib.py", line 299, in
http_error
    result = method(url, fp, errcode, errmsg, headers)
  File "/scratch1/dusty/python/lib/python2.0/urllib.py", line 534, in
http_error_302
    return self.open(newurl)
  File "/scratch1/dusty/python/lib/python2.0/urllib.py", line 166, in
open
    return getattr(self,
name)(url)                                                       
.....
------- snip --------

Then the program stops with this error:
------- snip---------
  File "/scratch1/dusty/python/lib/python2.0/urllib.py", line 166, in
open
    return getattr(self, name)(url)
  File "/scratch1/dusty/python/lib/python2.0/urllib.py", line 280, in
open_http
    errcode, errmsg, headers = h.getreply()
  File "/scratch1/dusty/python/lib/python2.0/httplib.py", line 683, in
getreply
    response = self._conn.getresponse()
  File "/scratch1/dusty/python/lib/python2.0/httplib.py", line 542, in
getresponse
    response.begin()
  File "/scratch1/dusty/python/lib/python2.0/httplib.py", line 144, in
begin
    self.msg = mimetools.Message(self.fp, 0)
  File "/scratch1/dusty/python/lib/python2.0/mimetools.py", line 15, in
__init__
    rfc822.Message.__init__(self, fp, seekable)
RuntimeError: Maximum recursion depth exceeded 
-------- snip ---------

This output is from python 2.0 but the same behavior occurs with 1.5.X,
only the line numbers differ.

If I execute this program on a machine behind a proxy, it works
properly, the proxy (squid) outputs a logentry like this:
989830411.012    916 192.168.0.2 TCP_MISS/000 2963 GET
http://www.sms.at/ - DIRECT/www.sms.at - 

I did a little traceback and inserted in urllib.py at line 285 in
function "open_http(self,url,data=None)"

if data is None:
<  print url,fp,errcode,errmsg,headers
<  sys.exit(1)
   return self.http_error(url, fp, errcode, errmsg, headers)

The output looks like this:
//www.sms.at <open file '<socket>', mode 'rb' at 0x8203010> 302 Object
moved Location: //www.sms.at/  

It seems that the page "http://www.sms.at" does a redirect at itself,
but this is somehow weird as this does not make any sense. Moreover I
don´t understand why my program works behind a proxy.

Do you have any clues?

		Best Regards,
		Hermann
-- 
 ,_,
(O,O)     "There is more to life than increasing its speed."
(   )     -- Gandhi
-"-"--------------------------------------------------------------



More information about the Python-list mailing list