HTTP Response Header Information in Python
Sometimes we need to get the HTTP Response header from our program. You can check the following python code, that prints the http response header:
If you want to get the value of a particular item, use the get() method:
Hope you will find this tips useful!
>>> import urllib2
>>> usock = urllib2.urlopen('http://bdosn.org')
>>> print usock.info()
Date: Thu, 24 Jul 2008 19:52:53 GMT
Server: Apache/1.3.39 (Unix) PHP/5.2.3 mod_auth_passthrough/1.8 mod_log_bytes/1.2 mod_bwlimited/1.4 mod_gzip/1.3.26.1a FrontPage/5.0.2.2634a mod_ssl/2.8.30 OpenSSL/0.9.7a
X-Powered-By: PHP/5.2.3
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html
>>>
If you want to get the value of a particular item, use the get() method:
>>> print usock.info().get('Date')
Thu, 24 Jul 2008 19:52:53 GMT
>>>
Hope you will find this tips useful!
Comments
Thanks