Home/Support/Support Forum/python web
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

python web

0 votes
hi,

using connectport x4.
how to retrieve result from python script on a web page. x4 does not support cgi as i understand. can anyone give a clue on how to simply print python result in an uploaded html form?
asked Jun 8, 2009 in Python by simakas New to the Community (22 points)

Please log in or register to answer this question.

10 Answers

0 votes
There are a few ways to accomplish what you are trying to do. One way in particular can involve direct callouts from the Digi web server to a python script via the "digiweb" module. Have you examined this module?
answered Jun 8, 2009 by 52637p Community Contributor (59 points)
0 votes
for reference: http://www.digi.com/wiki/developer/index.php/Module:digiweb
answered Jun 8, 2009 by clohfink New to the Community (27 points)
0 votes
will check that later.
answered Jun 9, 2009 by simakas New to the Community (22 points)
0 votes
can anyone give a clue, or a working example, because in documentation its not clear: should html be formed by python or python calls can be initiated from html.
cant get both ways working.

s.
answered Jun 11, 2009 by simakas New to the Community (22 points)
0 votes
If you're using the digiweb module that was linked previously, the callback that is registered forms the HTML to be returned as a string and returns that as the second element of the return tuple. For HTML, the first element should be the constant digiweb.TextHtml. That will cause the internal web server on the Digi box to return the web page you've generated.

There are two good examples on the wiki page. In the first one, you can see the template object is the form that all pages that example returns will take. It just fills in a few fields in the string to customize it for the particular request. If you have specific page locations that you would like to serve with different content, you would do the same, but base what you return on the path value passed into the callback.
answered Jun 11, 2009 by DigiGuy42 Community Contributor (102 points)
0 votes
hi,

could you please link to those examples you are talking about.
can anyone suggest simple explanation of how things must be done. following examples i cant get the generated content, the browser retrieves example source (like it was a .txt file). behavior is different using FF ant IE.
has anyone tried this with X4? it seems web server does not support digiweb. firmware 2.8.4.7

simon
answered Jun 12, 2009 by simakas New to the Community (22 points)
0 votes
the digiweb module was added in 2.8.0. so it should be in your firmware. I think the simplest you can get is the following:
Telnet to your device, type python and hit enter to enter the interactive console and type the following:
import digiweb
x= digiweb.Callback(lambda type, path, headers, args:(digiweb.TextHtml, "Worked") )
then from web browser go to http://[device address]/test
should print out "Worked"

If they work then look at the examples at the end of the page in http://www.digi.com/wiki/developer/index.php/Module:digiweb Can also check out http://www.digi.com/wiki/developer/index.php/Category:Web_Access


Message was edited by: clohfink
(added links)
answered Jun 12, 2009 by clohfink New to the Community (27 points)
0 votes
thanks for reply,
something is wrong. from your post i understand the principle is to run python console waiting, only then interact with web interface.
first, py console doesn't wait, if no parameters given - it executes with error, if given a python file with you example source - it executes immediately and exits.
second - there is no path like "test", the whole web content is hosted from /FS/WEB, python content /FS/WEB/python.

thanks again for cooperation,
reply is very much appreciated

s
answered Jun 15, 2009 by simakas New to the Community (22 points)
0 votes
The intention was to follow the instructions step-by-step.

The first was to telnet to the device and to enter the two lines to our interactive console, not to place them into an uploaded script. Since the interactive console remains active after the two commands are entered, you are able to observe the effect that they have had to the system.

The relative path "test" is arbitrary... chosen specifically because it is not an existing path.

The way the "digiweb" module works is that it is given the opportunity to service any otherwise unresolved path. In a more complete example, the callback function would examine the path parameter, and serve an appropriate page, or no pages.

The information pages that were referenced above have more complete examples that can, if you wish, be simply entered and run from the filesystem. They are worth examining.


Message was edited by: 52637p
answered Jun 15, 2009 by 52637p Community Contributor (59 points)
0 votes
Hello,
I'm trying to use the module "digiweb" on a Digi Transport WR41, but It seems not working.
In order to test it I used the code posted before:

import digiweb
x= digiweb.Callback(lambda type, path, headers, args:(digiweb.TextHtml, "Worked") )


The results is that every url I try (es: http://router_address/test) drive me to the logi page.
Can someone help me?
Greeting,
Marco
answered Dec 1, 2010 by sintex New to the Community (2 points)
...