Posts: 10
Registered: ‎05-08-2017
Accepted Solution

CM Python API



I am trying to use cm python api, but it keeps failing out. Not sure, what is causing the issue. I get 404 error ! which I think represents object not found.


Below is the code snippet



import datetime
import getpass
import re

from cm_api.api_client import ApiResource

# Connection information.
port = 7180
user = 'admin'
password = 'admin'

api = ApiResource(host, 7180, user, password)

# Finds the first YARN service in the first cluster.
cluster = api.get_all_clusters()[0]



Its failing with Message


Traceback (most recent call last):
  File "", line 23, in <module>
    cluster = api.get_all_clusters()[0]
  File "/usr/lib/python2.6/site-packages/cm_api/", line 131, in get_all_clusters
    return clusters.get_all_clusters(self, view)
  File "/usr/lib/python2.6/site-packages/cm_api/endpoints/", line 66, in get_all_clusters
    params=view and dict(view=view) or None)
  File "/usr/lib/python2.6/site-packages/cm_api/endpoints/", line 139, in call
    ret = method(path, params=params)
  File "/usr/lib/python2.6/site-packages/cm_api/", line 110, in get
    return self.invoke("GET", relpath, params)
  File "/usr/lib/python2.6/site-packages/cm_api/", line 73, in invoke
  File "/usr/lib/python2.6/site-packages/cm_api/", line 183, in execute
    raise self._exc_class(ex)
cm_api.api_client.ApiException:  (error 404)

Is it because of running python 2.6 ? I am running this on NameNode in my lab cluster(6 Node) that is running outside the production CM cluster. I am trying to use the API to connect to production cluster to fetch some metrics, but it keeps erroring out.


Also, We have RM HA. Is there a way to find which node is my active Resource Manager ? and the URL for it ? without logging into CM ?



Posts: 10
Registered: ‎05-08-2017

Re: CM Python API

Any thoughts or direction is appreciated 

Posts: 1,116
Topics: 1
Kudos: 287
Solutions: 135
Registered: ‎04-22-2014

Re: CM Python API

Hi @code0404,


The 404 message that you describe usually occurs when you are using the latest Python API but your Cloudera Manager does not support that latest API version.


Use the REST API to verify the maximum supported API version in your Cloudera Manager:




The output will be the supported version. For example, "v14".

Take that value and then use it in your ApiResource() like this:


api = ApiResource(host, 7180, user, password,version=14

   See the following for more information on ApiResource:





Posts: 10
Registered: ‎05-08-2017

Re: CM Python API

Wow, Thanks... worked perfect after I plugged in the version.