[Python-Dev] HTTP responses and errors

"Martin v. Löwis" martin at v.loewis.de
Tue Mar 27 16:48:02 CEST 2007

> Why only 200 and 206? 

This kind of question can often be answered through the revision
history. If you do 'svn annotate', you see that the line testing
for 206 was last changed in r36262. Comparing that to the
previous revision, you see that it before said

     if r.status == 200:

and that amk changed it with the log message

[Bug #912845] urllib2 only checks for a 200 return code, but 206 is also 
legal if a Range: header was supplied.
(Actually, should the first 'if' statement be modified to allow any 2xx 
status code?)

Going to bugs.python.org/912845, you see that the current form was 
proposed by Ahmed F. (oneofone), apparently because it crashed for
him with 206. In 2006, heresiarch ask the same question that you
are now asking and that amk asked before.

Going further back, you see that HTTPErrorProcessor (along with
the handling of 200) as added by jhylton in 34909, which in turn
originates from #852995, where jjlee introduced the handlers
in order to support cookie handling. Looking at the change, you
see that it is just refactoring; the special-casing of 200 was
present before.

In earlier versions, the error handling was done using this block:

  14267    jhylton         if code == 200:
  14267    jhylton             return addinfourl(fp, hdrs, 
  14267    jhylton         else:
  14267    jhylton             return self.parent.error('http', req, fp, 
code, msg, hdrs)

You then find that 14267 is the initial revision, checked in with
the comment

# An extensible library for opening URLs using a variety protocols.
# Intended as a replacement for urllib.

So it seems that it only tests for 200 and 206 because the experiments
never produced a need for anything else.


More information about the Python-Dev mailing list