The transition to NetApp MS Azure AD B2C is complete. If you missed the pre-registration, you will be invited to reigister at next log in.
Please note that access to your NetApp data may take up to 1 hour.
To learn more, read the FAQ and watch the video.
Need assistance? Complete this form and select “Registration Issue” as the Feedback Category.

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
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