Reply
Master
Posts: 315
Registered: ‎07-01-2015
Accepted Solution

Cannot access cluster via cm_api

Hi,

 I am using cm_api to get the information about the newly deployed cluster from ClouderaDirector.
My code was working until yesterday, and now sudenly it gives me this error:
 
CDH Environment CDHTEST Environment
Traceback (most recent call last):
  File "/tmp/get_cluster_info2.py", line 45, in <module>
    ( ci, clName ) = getClusterInstance( client )
  File "/tmp/get_cluster_info2.py", line 42, in getClusterInstance
    ci = c.get( cdhenvName , cdhdepName , clName )
  File "/usr/lib/python2.7/site-packages/cloudera/director/latest/ClustersApi.py", line 312, in get
    responseObject = self.apiClient.deserialize(response, 'cloudera.director.latest.models.Cluster')
  File "/usr/lib/python2.7/site-packages/cloudera/director/common/client.py", line 264, in deserialize
    subClass))
  File "/usr/lib/python2.7/site-packages/cloudera/director/common/client.py", line 268, in deserialize
    attrType))
  File "/usr/lib/python2.7/site-packages/cloudera/director/common/client.py", line 268, in deserialize
    attrType))
  File "/usr/lib/python2.7/site-packages/cloudera/director/common/client.py", line 264, in deserialize
    subClass))
  File "/usr/lib/python2.7/site-packages/cloudera/director/common/client.py", line 230, in deserialize
    return objClass(obj)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 5442-5445: ordinal not in range(128)
 
cm_api version 19.1.1
cloudera director verison 2.8.0 
 
The code:
 
import re
from cloudera.director.latest import ClustersApi
from cloudera.director.latest import EnvironmentsApi
from cloudera.director.latest import DeploymentsApi
from cloudera.director.common.client import ApiClient
from cloudera.director.latest import AuthenticationApi
from cloudera.director.latest.models import Login
from cm_api.api_client import ApiResource, ApiException, API_CURRENT_VERSION
import ssl
from socket import socket
from subprocess import Popen, PIPE
from time import sleep
 
username='admin'
password='admin'
  
client = ApiClient('http://localhost:7189', tls_enabled=False, cafile=None,  hostname_verification_enabled=True)
auth = AuthenticationApi(client)
auth.login(Login(username=username, password=password))
 
def getClusterInstance( apiclient ):
    cdhenv=EnvironmentsApi(apiclient)
    cdhenvName = cdhenv.list()[0]
    print('CDH Environment '+cdhenvName)
    cdhdep=DeploymentsApi(apiclient)
    cdhdepName = cdhdep.list( cdhenvName )[0]
    c=ClustersApi(apiclient)
    clName = c.list( cdhenvName, cdhdepName )[0]
    ci = c.get( cdhenvName , cdhdepName , clName )
    return ( ci, clName )
 
( ci, clName ) = getClusterInstance( client )
-> Here it fails
 
Master
Posts: 315
Registered: ‎07-01-2015

Re: Cannot access cluster via cm_api

The problem was that the response contained an unicode string, and client.py from commnon tried to cast it to str.

 

The hotfix:

 

awk 'NR==230{print "            if objClass in [str]:\n               return objClass(obj.encode(\"utf-8\"))"}1'  /usr/lib/python2.7/site-packages/cloudera/director/common/client.py | sudo tee /usr/lib/python2.7/site-packages/cloudera/director/common/client.py
Cloudera Employee
Posts: 69
Registered: ‎02-18-2014

Re: Cannot access cluster via cm_api

Hi Tomas79,

 

Thanks for bringing up this issue! I've filed an internal trouble ticket for this failure to handle Unicode, so that we can address it in a future release.

Master
Posts: 315
Registered: ‎07-01-2015

Re: Cannot access cluster via cm_api

I am glad that I could help
T.
Announcements