Hi I was trying to invoke the rest call from python-urllib2 .I see that It fails with 403 error.I feel its because there is no realm value. I am unable to find the WWW-Authenticate: value to find the realm value. Can you please help me with this.
Thanks >>> import urllib2 >>> url = 'http://localhost:8080/api/v1/clusters/' >>> password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm() >>> handler = urllib2.HTTPBasicAuthHandler(password_mgr) >>> password_mgr.add_password(None,'http://localhost:8080','admin', 'admin') >>> opener.open('http://localhost:8080/api/v1/clusters/') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib64/python2.6/urllib2.py", line 397, in open response = meth(req, response) File "/usr/lib64/python2.6/urllib2.py", line 510, in http_response 'http', request, response, code, msg, hdrs) File "/usr/lib64/python2.6/urllib2.py", line 435, in error return self._call_chain(*args) File "/usr/lib64/python2.6/urllib2.py", line 369, in _call_chain result = func(*args) File "/usr/lib64/python2.6/urllib2.py", line 518, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) urllib2.HTTPError: HTTP Error 403: Full authentication is required to access this resource I am able to use the pycurl library to get the response. >>> import pycurl, json >>> url = 'http://localhost:8080/api/v1/clusters/' >>> c = pycurl.Curl() >>> c.setopt(pycurl.URL, url) >>> c.setopt(pycurl.USERPWD,'admin') >>> c.setopt(pycurl.USERPWD,'admin:admin') >>> c.perform() { "href" : "http://localhost:8080/api/v1/clusters/", "items" : [ { "href" : "http://localhost:8080/api/v1/clusters/test1", "Clusters" : { "cluster_name" : "test1", "version" : "HDP-1.2.0" } } ] }
