Reading only headers

S.Selvam s.selvamsiva at
Thu Apr 9 12:13:08 CEST 2009

Hi all,

I want to read headers from web page and check whether its Content-Type is
xml or not.I used the following code
 request = urllib2.Request(url, None, USER_AGENT)
 opener = urllib2.build_opener()
 datastream =
 if datastream.headers.get('Content-Type','').find('xml') == -1:
            raise "Its not xml!"
      Read the content and process

Is this the good way to read headers ? ,as i do not want the content ,unless
it is xml.
Please suggest me,if there are some other good methods to read only the
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list