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('https://pythonexamples.org/')
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('https://pythonexamples.org/')
print(response.headers)
Run Code CopyOutput
{'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.
Next Topic ⫸ Python Requests - Send Parameters in URL
⫷ Previous Topic Python Requests - PATCH