Python Discussions

NaElement instance has no attribute 'replace'

JonathanSneep
4,123 Views

I'm trying to run a simple volume-get-iter against a number of our clusters, and then using xmltodict I want to convert the XML to a dictionary so that I can simply dump it in json format. It's working fine for all but one of our cdot clusters, but I think it's breaking on a cluster where there may be an odd character in a volume name.

 

File "./y.py", line 39, in <module>
xml_parser = out.sprintf()
File "/local/mnt/netappsplunk/NaElement.py", line 236, in sprintf
s = s+c.sprintf(indent + "\t")
File "/local/mnt/netappsplunk/NaElement.py", line 236, in sprintf
s = s+c.sprintf(indent + "\t")
File "/local/mnt/netappsplunk/NaElement.py", line 236, in sprintf
s = s+c.sprintf(indent + "\t")
File "/local/mnt/netappsplunk/NaElement.py", line 236, in sprintf
s = s+c.sprintf(indent + "\t")
File "/local/mnt/netappsplunk/NaElement.py", line 239, in sprintf
s = s + str(self.element['content'])
UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in position 30: ordinal not in range(128)

 

I tried to just do a replace, but that fails:

 

out = (s.invoke_elem(volume_list)).replace('\\xa0', ' ')
AttributeError: NaElement instance has no attribute 'replace'

 

Is there a way to make this work?

1 ACCEPTED SOLUTION

JonathanSneep
4,092 Views

Solved, by adding the following to NaElement.py

I'm open to other ideas or educational comments though 🙂

 

sys.setdefaultencoding('utf-8')

 

View solution in original post

2 REPLIES 2

JonathanSneep
4,110 Views

I believe now that I should modify the sprintf function in NaElement, but i'm not sure exactly how.

JonathanSneep
4,093 Views

Solved, by adding the following to NaElement.py

I'm open to other ideas or educational comments though 🙂

 

sys.setdefaultencoding('utf-8')

 

Public