TAGS :Viewed: 5 - Published at: a few seconds ago

[ urllib2 + Basic authentication + CookieJar ]

is there a way to use both openers to access a RESP Api from HP QC, or a different library i can use. im currently having trouble with a redirection error message "The HTTP server returned a redirect error that would lead to an infinite loop". but i can only use one opener whether to authenticate or cache cookies.

import json
import urllib2
from cookielib import CookieJar

SERVER = "http://server"

if __name__ == "__main__":
    cj = CookieJar()
    authinfo = urllib2.HTTPPasswordMgrWithDefaultRealm()
    authpage = SERVER + "authentication-point/authenticate"
    authinfo.add_password(None, authpage, 'user', 'user')
    handler = urllib2.HTTPBasicAuthHandler(authinfo)
    cjopener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
    myopener = urllib2.build_opener(handler)
    f = myopener.open(authpage)

        response = urllib2.urlopen(SERVER + "rest/is-authenticated")
        print response.info()
        print response.json()

Answer 1

or a different library i can use