Reading only headers

S.Selvam s.selvamsiva at gmail.com
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 = opener.open(request)
 if datastream.headers.get('Content-Type','').find('xml') == -1:
            raise "Its not xml!"
 else:
    """
      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
headers.
-- 
Yours,
S.Selvam
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090409/694f55dc/attachment.html>


More information about the Python-list mailing list