Why doesn't Ocsigen run my python file?

The test.conf configuration file is as follows:

<ocsigen> <server> <port>*:8000</port> <logdir>/home/zaxis/tmp/log/</logdir> <datadir>/home/zaxis/tmp/data</datadir> <user>zaxis</user> <group>wheel</group> <charset>utf-8</charset> ...... <extension findlib-package="ocsigen_ext.cgimod"> <cgitimeout value="30"/> </extension> <extension findlib-package="ocsigen_ext.staticmod"/> ...... <site path="qachina" charset="utf-8"> <cgi root="cgi-bin" dir="/media/E/www/qachina/cgi-bin"/> <static dir="/media/E/www/qachina" /> </site> .... <commandpipe>/home/zaxis/tmp/ocsigen_command</commandpipe> </server> </ocsigen> 

Then I launched Ocsigen:

ocsigeocsigen -c test.conf

I can visit http://127.0.0.1:8000/qachina/index.htm . However, Ocsigen does not execute my python script in cgi-bin, but wants the browser to load it.

BTW, all python script files can be run directly in the shell.

 >head cgi-bin/nav.py #!/usr/bin/env python # -*- coding: utf-8 -*-enter code here ... 

I cannot visit the Ocsigen mailing list, so I am posting offers here.

+4
source share
4 answers

What is your version of Ocsigen?

I just tried with ocsigen 1.3.4 (the version currently being tested by Debian) and there seems to be an error (on the Ocsigen side) with your config fragment. What you want can be achieved with:

 <cgi regexp="cgi-bin/([^/]*)" dir="/usr/lib/cgi-bin/" script="\1" /> 

I just checked all running Ocsigen instances that I have access to, and they all use the "regexp" attribute. However, the documentation permits your version, and the server accepts it. One of these two alternatives is a mistake.

FYI, ocsigen works with the -V option.

+4
source

For each request on the site, Ocsigen tries the extensions listed in the order of the configuration file. In your case, it runs staticmod, which succeeds because cgi-bin is the directory existing in the directory specified by staticmod. If you want to try cgimod first, you must put <cgi ...> before <static ...> .

+5
source

I don’t know any solid answer, because it seems to me that it should work, but I have some questions that may be useful.

When you receive a download request, have you really downloaded it? If so, are you loading the webpage from the script, or are you loading the script yourself? If this is the first, then this is just a mime type question. If it comes later, it will most likely be a problem for the static module serving the page, and not for the CGI. Have you tried removing <static dir="/media/E/www/qachina" /> to see if this contradicts?

+2
source
 >cat /usr/ports/www/ocsigen/Makefile |grep -i version PORTVERSION= 1.1.0 >ocsigen -c test.conf -V [warnings.log] 2011-11-28 08:25:47 - Exception while creating IPv6 socket: Invalid argument in function bind () -- Dependencies of ocsigen_ext.redirectmod: ocsigen_ext.redirectmod -- Needed: /usr/local/lib/ocsigen/extensions/redirectmod.cmo Loading extension /usr/local/lib/ocsigen/extensions/redirectmod.cmo -- Dependencies of ocsigen_ext.cgimod: ocsigen_ext.cgimod -- Needed: /usr/local/lib/ocsigen/extensions/cgimod.cmo Loading extension /usr/local/lib/ocsigen/extensions/cgimod.cmo -- Dependencies of ocsigen_ext.staticmod: ocsigen_ext.staticmod -- Needed: /usr/local/lib/ocsigen/extensions/staticmod.cmo Loading extension /usr/local/lib/ocsigen/extensions/staticmod.cmo -- Dependencies of ocsigen_ext.ocsipersist-sqlite: sqlite3, ocsigen_ext.ocsipersist sqlite -- Needed: /usr/local/lib/ocaml/site-lib/sqlite3/sqlite3.cma, /usr/local/lib/ocsigen/ extensions/ocsipersist-sqlite.cma Loading extension /usr/local/lib/ocaml/site-lib/sqlite3/sqlite3.cma Loading extension /usr/local/lib/ocsigen/extensions/ocsipersist-sqlite.cma -- Dependencies of ocsigen_ext.eliom: num.core, num, cryptokit, ocsigen_ext.eliom -- Needed: /usr/local/lib/ocaml/nums.cma, /usr/local/lib/ocaml/site-lib/cryptokit cryptokit.cma, /usr/local/lib/ocsigen/extensions/eliom.cma Loading extension /usr/local/lib/ocaml/nums.cma Loading extension /usr/local/lib/ocaml/site-lib/cryptokit/cryptokit.cma Loading extension /usr/local/lib/ocsigen/extensions/eliom.cma [warnings.log] 2011-11-28 08:25:47 - While parsing config file, tag <host>: Assuming defaulthostname is "localhost" -- Dependencies of eliom_examples.miniwiki: eliom_examples.miniwiki -- Needed: /usr/local/lib/ocsigen/examples/miniwiki.cmo Loading /usr/local/lib/ocsigen/examples/miniwiki.cmo (will be reloaded every times) -- Dependencies of eliom_examples.tutoeliom: eliom_examples.tutoeliom -- Needed: /usr/local/lib/ocsigen/examples/tutoeliom.cmo Loading /usr/local/lib/ocsigen/examples/tutoeliom.cmo (will be reloaded every times) [warnings.log] 2011-11-28 08:25:47 - Reloading config file ... [warnings.log] 2011-11-28 08:25:47 - Config file reloaded [warnings.log] 2011-11-28 08:25:47 - Ocsigen has been launched (initialisations ok) 

When visiting http: // localhost: 8000 / qachina / cgi-bin / nav.py using Opera:

 GET /qachina/cgi-bin/nav.py HTTP/1.1 User-Agent: Opera/9.80 (X11; FreeBSD 8.2-RELEASE i386; U; zh-cn) Presto/2.9.168 Version/11.50 Host: localhost:8000 Accept: text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/webp, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1 Accept-Language: zh-CN,zh;q=0.9,en;q=0.8 Accept-Encoding: gzip, deflate Cache-Control: no-cache Connection: Keep-Alive - host=localhost [access.log] 2011-11-28 08:42:06 - connection for localhost from 127.0.0.1 (Opera/9.80 (X11; FreeBSD 8.2-RELEASE i386; U; zh-cn) Presto/2.9.168 Version/11.50): /qachina/cgi-bin/nav.py -------- host found! localhost:8000 matches * site "ocsigenstuff" does not match url "qachina/cgi-bin/nav.py". site "miniwiki" does not match url "qachina/cgi-bin/nav.py". -------- site found: url "qachina/cgi-bin/nav.py" matches "qachina". --Cgimod: Is it a cgi file? --Cgimod: Testing "/media/E/www/qachina/cgi-bin/nav.py". --Cgimod: Looking for "/media/E/www/qachina/cgi-bin/nav.py". ** Receiving HTTP message [warnings.log] 2011-11-28 08:42:06 - CGI says: env: python: No such file or directory Thread 10 killed on uncaught exception Invalid_argument("index out of bounds") [warnings.log] 2011-11-28 08:42:06 - CGI exited with code 127 ~~~ Exception during generation/sending: Ocsigen_http_com.Connection_closed 

[warnings.log] 2011-11-28 08:42:06 - Exn during page generation: Ocsigen_http_com.Connection_closed (sending 500) -> Sending 500 ...

After changing #!/usr/bin/env python to #!/usr/local/bin/python for each python file now it works!

thanks!

+1
source

Source: https://habr.com/ru/post/1383003/


All Articles