Python Discussions

NaElement instance has no attribute 'replace'

JonathanSneep

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

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

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

JonathanSneep

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

Announcements
Register for Insight 2021 Digital

INSIGHT 2021 Digital: Meet the Specialists 2

On October 20-22, gear up for a fully digital, totally immersive virtual experience with a downright legendary lineup of world-renowned specialists. Tune in for visionary conversations, solution deep dives, technical sessions and more.

NetApp on Discord Image

We're on Discord, are you?

Live Chat, Watch Parties, and More!

Explore Banner

Meet Explore, NetApp’s digital sales platform

Engage digitally throughout the sales process, from product discovery to configuration, and handle all your post-purchase needs.

NetApp Insights to Action
I2A Banner
Public