Python Requests – HTTP OPTIONS – Example

HTTP OPTIONS method describes the communication options for the target resource.

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/')
Run this program

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.

import requests

response = requests.options('https://pythonexamples.org/')
print(response.headers)
Run this program
{'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'}