Like to run python script " arduino.local/sd/myside/my_dynamic_side.py" on YUN

Hello

i like to build an dynamic webside on yun i load up it with a scetch like sketchfolder myscetch myscetch.ino www my_dynamic_side.py

the first line in my python file is

!/usr/bin/python

but when i try to test it arduino.local/sd/myside/my_dynamic_side.py

arduinos webserver ask me to download the script file

what iam doing wrong ?

Server side code (aka: dynamic web pages) must reside into the cgi-bin folder /www/cgi-bin
There currently is no way to make that page be transferred by the IDE (although that may be a good feature request to put on github)
You’ll need to manually copy that to /www/cgi-bin. Don’t forget to make your python script cgi aware. Google for python cgi

where is this cgi-bin folder ?

below my own www folder from my sketch ?

myscetch www cgi-bin

Sorry my post got strangely misformatted. The cgi-bin folder is on the yun, it's /www/cgi-bin. You need to use command line tools like scp, winscp to copy files from your computer to the yun

i dont understand this because my statik webside on yun works well

arduino.local/sd/myside/index.html

just when i call

arduino.local/sd/myside/my_dynamic_side.py

i got the answer from yun to download the file.
This means the file is allready placed on yun but the webserver have no idea what is to do with the file.

So i think the yun webserver do not found the python interpreter.

your python script will be run by the webserver IF

If you are new to cgi web development, I suggest you first get acquainted with it.
You also wnat to search this forum as someone else has already played with it

So i think the yun webserver do not found the python interpreter.

You have to edit the config file:

/etc/config/uhttpd

I have ammended this line:

list interpreter ".cgi=/usr/bin/python"

When you are finished, restart the webserver:

/etc/init.d/uhttpd restart

I rename my python scripts with the extension .cgi, eg test.cgi

thanks erni, thanks all

have insertet
list interpreter “.py=/usr/bin/python”
in uhttpd with putty
restart and it works :slight_smile: :slight_smile:

index.html

Übertragung von Formularinhalten

Gib Deinen Namen ein!

Dein Name:

Passwort :

cgi_formular_auswertung.py

#-- coding: utf-8 --

import cgi

Das aufrufende Programm ist ein normales html-Dokument

In Python wird, ähnlich wie in PHP, Python-Code gemischt mit

HTML-Anweisungen.

Mit einer Instanz der Klasse FieldStorage können wir auf durch

POST oder GET übertragene Daten zugreifen.

Lange Texte können mit print “”" mehrzeiliger Text “”" ausgegeben

werden. Die Angabe der Sprachcodierung UTF-8 ermöglicht es, direkt

mit Umlauten in HTML-Texten zu arbeiten.

print “Content-type: text/html; charset=UTF-8”
print # Leerzeile (muss sein!)

print “”"

Übertragung von Formularinhalten

Die übertragenen Daten.

"""

form=cgi.FieldStorage()
s1=form[“Anwender”].value
s2=form[“Passwort”].value

if form.getvalue(“Textfeld”):
text= form.getvalue(“Textfeld”)
else:
text= “keine Eingabe”

print "

Dein Name lautet, :", s1,"

"
print “

Passwort : “,s2,”

print “

Der folgende Text wurde eingegeben:”,text,"

"
print " "

Today I've learnt something new, thanks Erni :)

i have also installed php works great too :)

OttoF, can you please post HelloWorld example of .py file.

I inserted: list interpreter ".py=/usr/bin/python", restart uhttpd, but when accessing .py file, I get error

"Bad Gateway The process did not produce any response"

I think that I have to properly format py file or response in it. Since I am new to python, please provide me with print "Hello world" example of python file.

OttoF: i dont understand this because my statik webside on yun works well

arduino.local/sd/myside/index.html

just when i call

arduino.local/sd/myside/my_dynamic_side.py

i got the answer from yun to download the file. This means the file is allready placed on yun but the webserver have no idea what is to do with the file.

So i think the yun webserver do not found the python interpreter.

Of course not, as a Python source file is not per se a web browser file like the html file is. You basically are trying to create a catch 22 situation: You need to first invoke the web browser with an html file, which can trigger the Python script being called, which in turn emitts more html code, which the web browser then can execute/interpret...

[ur=http://docs.python.org/2/howto/webservers.htmll]HOWTO Use Python in the web[/url]

Ralf

Ok! Found out.

This is minimal Hello world example of python web served script:

print print "Hello World!"

Hi!

I tried setting the "uhttpd" file and have not succeeded. Could you explain how to access "/ etc / config / uhttpd"? and how can I make the setting "list interpreter" .cgi = / usr / bin / python?

yo llevo un mes intentando y no lo he conseguido :(

Python as CGI at uhttpd

OttoF:
thanks erni, thanks all

have insertet
list interpreter “.py=/usr/bin/python”
in uhttpd with putty
restart and it works :slight_smile: :slight_smile:

How you inserted list interpreter ".py = / usr / bin / python "? I get this:

root@jdcyun:/etc/config# cd uhttp
-ash: cd: can’t cd to uhttp
root@jdcyun:/etc/config#

and and I’ve tried:

root@jdcyun:/etc/config# uhttpd list interpreter “.py=usr/bin/python”
Error: No sockets bound, unable to continue
root@jdcyun:/etc/config#

I’m using putty

@juanp-delacruz, in future, please start a new thread. Your answer will be buried.

The purpose of starting a new thread is to help other people with similar problems. One thread, one problem, one solution.

On your issue, uhttpd comes from OpenWrt, the base for Yun-OS. So Google: openwrt uhttpd config

There are the important webpages for you:

TIA Jesse