Tag Archives: Python

#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))
cookie_request = req.Request('url', method='POST')
resp = req.urlopen(cookie_request)