Tools, FAQ, Tutorials:
requests.models.Response Objects
What properties and functions are supported on requests.models.Response objects?
✍: FYIcenter.com
"requests" module supports the following properties and functions on requests.models.Response objects:
>>> r = requests.get() >>> r.status_code >>> r.headers # represents the headers as a dictionary >>> r.text # represents the response body as a strings >>> r.content # represents the response body as a binary >>> r.json() # parses the response body in JSON format >>> r.request # represents the request as requests.models.PreparedRequest >>> dir(r) ['__attrs__', ..., 'apparent_encoding', 'close', 'connection', 'content', 'cookies', 'elapsed', 'encoding', 'headers', 'history', 'is_permanent_redirect', 'is_redirect', 'iter_content', 'iter_lines', 'json', 'links', 'next', 'ok', 'raise_for_status', 'raw', 'reason', 'request', 'status_code', 'text', 'url' ]
Here is a Python example on how to access the HTTP response headers:
>>> import requests >>> r = requests.get('http://httpbin.org/get') >>> h = r.headers >>> print(h) {'Connection': 'keep-alive', 'Server': 'gunicorn/19.9.0', 'Date': 'Sun, 12 Aug 2018 21:51:53 GMT', 'Content-Type': 'application/json', 'Content-Length': '265', 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Credentials': 'true', 'Via': '1.1 vegur' }
⇒ Sending an HTTP POST Request
⇐ Sending an HTTP Request with 'requests'
2024-04-02, 39397🔥, 2💬
Popular Posts:
How To Pad an Array with the Same Value Multiple Times in PHP? If you want to add the same value mul...
How to use the "send-one-way-request" Policy statement to call an extra web service for an Azure API...
How to pull NVIDIA CUDA Docker Image with the "docker image pull nvidia/cuda" command? If you are ru...
How to login to Azure API Management Publisher Dashboard? If you have given access permission to an ...
How to use the "set-backend-service" Policy Statement for an Azure API service operation? The "set-b...