your issue is with this line...

    xmlstr = ET.tostring(tree,encoding=None)

might want to try it out in your python repl before modifying your 
controller.

On Wednesday, April 2, 2014 1:14:11 PM UTC-7, Ramesh Aj wrote:
>
> I have controller in web2py as below
>
> # coding: utf8
> # try something like
> #!/usr/local/python2.7
> def index():
>     import pexpect
>     import sys
>     import time
>     import cgi, cgitb
>     import getpass
>     import urllib3
>     import elementtree.ElementTree as ET
>     
>     ssh_cmd = 'ssh -t'
>     username = 'admin'
>     ip_addr = '192.***.***.***'
>     login = 'logging root'
>     password = 'password'
>     command = ssh_cmd+" "+username+"@"+ip_addr+" "+login
>     try:
>         child = pexpect.spawn(command)
>         child.expect('(?i)password')
>         child.sendline('admin')
>         child.expect('(?i)Password:')
>         child.sendline('abghtnnppst')
>         child.expect('-bash# ')
>         child.sendline('cd /root/siby')
>         child.expect('-bash# ')
>         child.sendline('perl analyzer_main.pl -s -i all')
>         child.expect('-bash# ')
>     except Exception, e:
>             print e
>     print child.before
>     lines = child.before
>     results = ET.Element("results")
>
>     for line in lines.split("\n"):
>         if 'MAC' in line:
>             station = ET.SubElement(results,"machine")
>             stnmac = ET.SubElement(machine,"mac")
>             stnip = ET.SubElement(machine,"ip")
>             apidname = ET.SubElement(machine,"name")
>             totalxput = ET.SubElement(machine,"input")
>             retry = ET.SubElement(machine, "retry")
>             
>         if 'MAC' in line:
>             mac = line.split(":", 1)
>             mac.text = str(mac[1].strip())
>         if 'IP' in line:
>             ip = line.split(":")
>             ip.text = str(ip[1].strip())
>         if 'NAME' in line:
>             name = line.split(":")
>             name.text = str(name[1].strip())
>         if 'input' in line:
>             input = line.split(":")
>             input.text = str(input[1].strip())
>         if 'Retry' in line:
>             ret = line.split(":")
>             retry.text = str(ret[1].strip())
>             tree = ET.ElementTree(results)
>     tree.write('station.xml')
>     sys.stdout.flush()
>     if child.isalive():
>         child.sendline('exit') # Try to ask ftp child to exit.
>         child.close()
>     if child.isalive():
>         print('Child did not exit gracefully.')
>     else:
>         print('Child exited gracefully.')
>     xmlstr = ET.tostring(tree,encoding=None)
>     return dict(xmlstr)
>
>
> In View I have the following code
>
> {{extend 'layout.html'}}
> <h1>This is the remotectrl/index.html template</h1>
> <body>
>     {{=XML(xmlstr)}}
> </body>
> {{=BEAUTIFY(response._vars)}}
>
> I want to print the XML data in webpage index.html
> But it is giving me exception 
>
> 8.
> 9.
> 10.
> 11.
> 12.
> 13.
> 14.
>
>
> Traceback (most recent call last):
>   File "/root/python2.7/Python-2.7.6/web2py/gluon/restricted.py", line 
> 220, in restricted
>     exec ccode in environment
>   File 
> "/root/python2.7/Python-2.7.6/web2py/applications/get_station/controllers/remotectrl.py",
>  
> line 88, in <module>
>   File "/root/python2.7/Python-2.7.6/web2py/gluon/globals.py", line 385, 
> in <lambda>
>     self._caller = lambda f: f()
>   File 
> "/root/python2.7/Python-2.7.6/web2py/applications/get_station/controllers/remotectrl.py",
>  
> line 85, in index
>     xmlstr = ET.tostring(tree,encoding=None)
>   File "build/bdist.linux-i686/egg/elementtree/ElementTree.py", line 1056, 
> in tostring
>     ElementTree(element).write(file, encoding)
>   File "build/bdist.linux-i686/egg/elementtree/ElementTree.py", line 584, 
> in __init__
>     assert element is None or iselement(element)
> AssertionError
>
> Error snapshot help
>
> <type 'exceptions.AssertionError'>() 
>
> Not sure what is the issue here, why is it not printing XML data in to 
> index.html ?
>
> Thanks for help
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to