Archives of Support Questions (Read Only)

This is an archived board for historical reference. Information and links may no longer be available or relevant
Announcements
This board is archived and read-only for historical reference. To ask a new question, please post a new topic on the appropriate active board.

cm_api.api_client.ApiException: HTTP Error 401: basic auth failed (error 401)

avatar
Contributor

Hi Friends,

 

Getting the following exception:

cm_api.api_client.ApiException: HTTP Error 401: basic auth failed (error 401)

 

CM is on the same host where I am executing the python script. Seems a very basic error. Passing admin CM credentials. Seeking pointers to 

- which port is it using?

- do I have to enable CM REST API?

- anyothers?

 

Complete stack trace.

 

[rizwmian@w0575oslshcea01 cluster_diff]$ python --version
Python 2.6.6
[rizwmian@w0575oslshcea01 cluster_diff]$ cdh.py
Traceback (most recent call last):
File "./cdh.py", line 67, in <module>
main()
File "./cdh.py", line 62, in main
cluster = find_cluster(api, None)
File "./cdh.py", line 12, in find_cluster
all_clusters = api.get_all_clusters()
File "/usr/lib/python2.6/site-packages/cm_api/api_client.py", line 128, in get_all_clusters
return clusters.get_all_clusters(self, view)
File "/usr/lib/python2.6/site-packages/cm_api/endpoints/clusters.py", line 66, in get_all_clusters
params=view and dict(view=view) or None)
File "/usr/lib/python2.6/site-packages/cm_api/endpoints/types.py", line 139, in call
ret = method(path, params=params)
File "/usr/lib/python2.6/site-packages/cm_api/resource.py", line 110, in get
return self.invoke("GET", relpath, params)
File "/usr/lib/python2.6/site-packages/cm_api/resource.py", line 73, in invoke
headers=headers)
File "/usr/lib/python2.6/site-packages/cm_api/http_client.py", line 174, in execute
raise self._exc_class(ex)
cm_api.api_client.ApiException: HTTP Error 401: basic auth failed (error 401)

 

cm_api.api_client.ApiException: HTTP Error 401: basic auth failed (error 401)

1 ACCEPTED SOLUTION

avatar
Contributor

Figured out. Need both:
- username/password to connect to cm api
- user launching script to have valid kerberos ticket (surprising find)

 

Thanks everyone. 🙂

View solution in original post

4 REPLIES 4

avatar
Contributor

Figured out. Need both:
- username/password to connect to cm api
- user launching script to have valid kerberos ticket (surprising find)

 

Thanks everyone. 🙂

avatar
New Contributor

Hello,

i am also facing the same issue . can you please elaborate what exactly you did.

 

Thank you.

 

-avi

avatar
Master Guru

@ParidaAbinash

 

In order to use the API, you must provide authenticate to CM.  See the example here:

https://cloudera.github.io/cm_api/docs/python-client/

 

# Get a handle to the API client
from cm_api.api_client import ApiResource

cm_host = "cm-host"
api = ApiResource(cm_host, username="admin", password="admin")

# Get a list of all clusters
cdh4 = None
for c in api.get_all_clusters():
  print c.name
  if c.version == "CDH4":
    cdh4 = c

avatar
New Contributor

Thanks ,

i figured out the issue.

i was passing the credentials but as it was a new service id , i had not added it with our hadoop group.

so the credential also couldnot be logged in to cloudera manager (which i hadnt checked earlier ,as it was working fine while logging into the server )