Requests - HTTP OPTIONS - Python Examples
HTTP Options
HTTP OPTIONS method describes the communication options for the target resource identified by the given URL.
Example
In Python Requests library, requests.post() method is used to send a OPTIONS request to a server over HTTP.
import requests
response = requests.options('/')
requests.options() returns a Response object. It contains all the data and properties like response content, headers, encoding, cookies, etc. Let us print out headers.
Python Program
import requests
response = requests.options('/')
print(response.headers)
Output
{'Date': 'Mon, 25 Mar 2019 14:20:57 GMT', 'Content-Length': '0', 'Connection': 'keep-alive', 'Keep-Alive': 'timeout=30', 'Server': 'Apache/2', 'Vary': 'Accept-Encoding', 'Allow': 'OPTIONS,GET,HEAD,POST,TRACE', 'Referrer-Policy': 'no-referrer-when-downgrade'}
Summary
In this Python Tutorial, we learned about HTTP OPTIONS in requests module.