password_mgr = request.HTTPPasswordMgrWithDefaultRealm() password_mgr.add_password(None, top_level_url, username, password) handler = request.HTTPBasicAuthHandler(password_mgr) opener = request.build_opener(handler) a_url = top_level_url + "/_cluster/stats" resultData = opener.open(a_url) resultData = json.loads(resultData.read().decode())