0

I'm running the following python program to read the content of a file, but the outcome is presented in HEX as follow:

Python Script:

import sys
sys.path.append("<path_to_nmsdk_root>/lib/python/NetApp")
from NaServer import *

s = NaServer("<server name or IP address>", 1 , 17)
s.set_server_type("FILER")
s.set_transport_type("HTTPS")
s.set_port(443)
s.set_style("LOGIN")
s.set_admin_user("<user name>", "<password>")

api = NaElement("file-read-file")
api.child_add_string("length","<length>")
api.child_add_string("offset","<offset>")
api.child_add_string("path","<path>")
xo = s.invoke_elem(api)
if (xo.results_status() == "failed") :
    print ("Error:\n")
    print (xo.sprintf())
    sys.exit (1)
print ("Received:\n")
print (xo.sprintf())

The output is:

< results status="passed">
< length>3419< /length>
**< data>2f 75 70 6c 6f 61 64 2f 63 6f 6d 6d 6f 6e 2f 75 73 65 72 73 3a 20 4e 65 77 20 53 70 61 63 65 20 41 76 61 69 6c 61 62 6c 65</data>**


I'd like to get the result in ASCII, which should be:

< data>/upload/common/users: New Space Available< /data>

Dolda2000
  • 25,216
  • 4
  • 51
  • 92
Oscar
  • 33
  • 4
  • Does all that output come out from the `print(xo.sprintf())`? It's not totally clear from your post. – lurker Apr 04 '15 at 00:28
  • That is correct. The print (xo.sprintf()) provides the output. I just read that I can import binascii and use a parameter to get the output in ASCII. I'm not sure if that can be added to sprintf(?) – Oscar Apr 04 '15 at 00:31
  • 1
    You'd need to check the documentation for the NaServer library. The `sprintf` is a method specifically associated with the object returned from `invoke_elem`. – lurker Apr 04 '15 at 00:32
  • Thanks for pointing that out and your fast response. I just looked at the library and there is a parameter in the api called "data". It says "Data read from the file. The format of the data is ASCII hex characters, two characters representing one byte from the file. (This format allows the representation of 0-valued bytes)." So I believe this is called by the NaElement. – Oscar Apr 04 '15 at 00:46
  • I would look for other methods provide by the type of object that `xo` is. If it provides an `sprintf()` method that just does an ASCII dump of its contents, it might also have other methods to obtain individual components in a more convenient form. If not, you're stuck having to parse the ASCII yourself using Python string class methods. – lurker Apr 04 '15 at 00:50
  • I need to investigate the "s.invoke_elem" to see if it can be manipulated. I will try to find another way to print xo without using sprintf(). – Oscar Apr 04 '15 at 01:00

0 Answers0