[web2py] How to load processed values in same page as form exists ?
I have created a form that takes server ip, username and password. I use pexpect to ssh into remote server, run a particular command and get basic data related to that server. I am creating the form using controller and also doing ssh in same controller and returning both form and processed data from same controller. But, when I run the html it is not displaying correct result, I am also confused on how I can load a table below add button inside a same page but as different frame. My Controller script as below: # coding: utf8# try something likedef display(): import pexpect import sys import time import cgi, cgitb import getpass import urllib3 import xml.etree.ElementTree as ET import json attr = ["Hostname", "Model Name", "Version", "connected count", "online Count"] form=FORM(DIV('server IP', INPUT(_name = 'ipaddr', requires = IS_NOT_EMPTY()), 'Username', INPUT(_name = 'uname', requires = IS_NOT_EMPTY()), 'Password',INPUT(_name = 'password', _type = 'password', requires = IS_NOT_EMPTY()), INPUT(_value='Add',_type='submit'))) valuelist = list() if form.accepts(request,session): response.flash = 'form accepted' ssh_cmd = 'ssh' username = request.vars['uname'].strip() ip_addr = request.vars['ipaddr'].strip() password = request.vars['password'].strip() command = ssh_cmd+" "+username+"@"+ip_addr try: child = pexpect.spawn(command) child.expect('(?i)password') child.sendline(password) child.expect('bash2.1# ') child.sendline('show sys-summary general') child.expect('bash2.1# ') except Exception, e: print e print child.before lines = child.before for line in lines.split("\n"): if any(word in line for word in attr): keyValue = line.split(":", 1) value = keyValue[1].strip() valuelist.append(value) 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.') elif form.errors: response.flash = 'form has errors' else: response.flash = 'please fill the form' return dict(form=form, valuelist=valuelist) Now my html code is as below. It is just simple and I want to test whether that particular values has been received accordingly or not, hence I am just calling returned value View code is: {{extend 'layout.html'}}Controller Page{{=form}}Submitted variables{{=valuelist}}Accepted variables{{=BEAUTIFY(form.vars)}}Errors in form{{=BEAUTIFY(form.errors)}} Could some one suggest, what change I can make so that I can see details of server below add button itself ? Like Server IP: Username: Password: add 222.222.222.222 examplehostname 333modelno 3.2 44 connected 22 online Thanks ! -- 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] JSON data in HTML web page
I am reading data from remote machine and converting it into dictionary format like {IP: [192.111.111.111, 222.222.222.222, 333.333.333.333], "MAC": [aa:aa:aa:aa, bb:bb:bb:bb, cc:cc:cc:cc], "conn": [wireless, wireless, wireless]} I am sending this dictionary to view which is index.html where I am dumping this as json.dumps(mydict) Now, I want to take this json data and format in a specific way so that I can display on html page (index.html) How would I do that ? Can I write jquery in index.html(view) or how would I read json data and print it in proper readable format ? Thanks ! -- 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] gluon.rocket.SocketTimeout'>(Socket timed out before request Error
The Following code is giving "gluon.rocket.SocketTimeout'>(Socket timed out before request" error {{extend 'layout.html'}} {{import xml.etree.ElementTree as ET}} This is a Stations detail page {{ filename = xmlfile with open(filename, mode="r") as fp: for line in fp: print line fp.close() =BEAUTIFY(response._vars) }} Can somebody suggest what could be issue? -- 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Exception in importing pexpect
I am trying to spawn a shell to remote machine in web2py and I am getting following exception Cannot import module 'pexpect' -- 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Exception seen for controller in web2py
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'}} This is the remotectrl/index.html template {{=XML(xmlstr)}} {{=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 File "/root/python2.7/Python-2.7.6/web2py/gluon/globals.py", line 385, in 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 () 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.