#Python to deal with HTTP with cookies

Recently needed to create a script to make HTTP calls along with handling of cookies, here is a code:

import urllib.request as req
from urllib.error import HTTPError
import http.cookiejar as cookie
 
cookie_jar = cookie.CookieJar()
opener = req.build_opener(req.HTTPCookieProcessor(cookie_jar))
req.install_opener(opener)
 
cookie_request = req.Request('url', method='POST')
resp = req.urlopen(cookie_request)

Leave a Reply

Your email address will not be published. Required fields are marked *