In Webhosting (called from Webbrowser) *most* Python scripts end with HTTP 500,
example www.mysite.com/python/mypycript.cgi
or www.mysite.com/anyfolder/mypage.html (html contains iframe to mypyscript.cgi)
However: These scripts can be successfully executed via commandline (via Putty),
example python mypyscript.cgi.
All are in the same folder.
scripts properties:
extension = .cgi
access-right = executable (744 or 705)
Example which cannot be executed:
#!/usr/bin/python
print ("hallo wd")
What can be the reason?
Bonjour,
Jetez un œil dans votre portail client > hébergement > journaux > journal d'erreurs web
Vous trouverez probablement un message d’erreur plus complet. Il se peut que Python ne soit pas pris en charge dans l’environnement qui exécute le serveur web (l’environnement ssh est différent). Ou bien le chemin vers l’exécutable python3 est incorrect.
thank you!
I found "06.04.26 20:05:04 | INFO | End of script output before headers: test3.py.cgi " which was not helpful.
Now I had two identical files, and one runs successfully the other brought an error when running via cgi.
Both however can run via commandline (in putty).
The difference is the kind of linebreaks:
o) unix x'0A' => successful
o) windows x'0D0A' => error
Is there a possibility to handle this problem? Maybe some config in webhosting (to accept windows linebreaks), filetransfer (to modify linesbreaks) or pycharm (to write unix linesbreaks).
and additional: the "print" output must start with
o) a header line plus empty line
o) or at least an empty line
# print("Content-type: text/html") .. optional
print("") # WICHTIG: Leerzeile!
Btw. is it possible to execute .py files (instead of needing to rename it to .cgi)?
test - previous reply got lost ?
[originally there was already a reply but it disappeared]
meanwhile I know the reason:
py-files had different linebreaks,
unix X'0A' - run successfully
windows X'0D0A' brought an error when called from browser, and successful via commandline (putty)