Tools, FAQ, Tutorials:
http.client.HTTPResponse Objects
What properties and functions are supported on http.client.HTTPResponse objects?
✍: FYIcenter.com
If you get an http.client.HTTPResponse object from a urlopen() function call,
you should be able use the following properties and functions:
>>> r = urllib.request.urlopen('http://httpbin.org/get')
>>> status # represents the response status code
>>> getcode() # returns the response status code
>>> getheaders() # returns the headers as a list object
>>> read() # returns the body as a binary
>>> url # represents the url where this response comes from
>>> dir(r)
['__abstractmethods__', ..., 'begin', 'chunk_left', 'chunked', 'close',
'closed', 'code', 'debuglevel', 'detach', 'fileno', 'flush', 'fp',
'getcode', 'getheader', 'getheaders', 'geturl', 'headers', 'info',
'isatty', 'isclosed', 'length', 'msg', 'peek', 'read', 'read1',
'readable', 'readinto', 'readinto1', 'readline', 'readlines', 'reason',
'seek', 'seekable', 'status', 'tell', 'truncate', 'url', 'version',
'will_close', 'writable', 'write', 'writelines']
Here is a Python example on how to access the HTTP response headers:
>>> import urllib
>>> r = urllib.request.urlopen('http://httpbin.org/get')
>>> h = r.getheaders()
>>> print(h)
[('Connection', 'close'), ('Server', 'gunicorn/19.9.0'),
('Date', 'Sun, 12 Aug 2018 23:41:01 GMT'),
('Content-Type', 'application/json'),
('Content-Length', '234'),
('Access-Control-Allow-Origin', '*'),
('Access-Control-Allow-Credentials','true'),
('Via', '1.1 vegur')]
⇒ HTTP POST with urllib.request
⇐ Sending an HTTP Request with 'urllib.request'
2018-09-24, ≈12🔥, 0💬
Popular Posts:
How To Move Uploaded Files To Permanent Directory in PHP? PHP stores uploaded files in a temporary d...
What Is Azure API Management Service? Azure API Management as a turnkey solution for publishing APIs...
Where to get a real Atom XML example? You can follow this tutorial to get a real Atom XML example: 1...
How to use "{{...}}" Liquid Codes in "set-body" Policy Statement? The "{{...}}" Liquid Codes in "set...
Tools, FAQ, Tutorials: JSON Validator JSON-XML Converter XML-JSON Converter JSON FAQ/Tutorials Pytho...