silverx Posted September 2, 2017 Posted September 2, 2017 Hello everyone. As the title implies, i am completely new to web hosting and web related stuff. I need help trying to figure out ho to run a script i wrote in Python. Could someone point me to a guide on how to run my script? Do i need something particular to transform a "regular python script" into something readeable by the web server? PS. My script uses the Google APIs. I would need the following package installed: Package: google-api-python-client Server: Johnny User: silverb Thank you for your patience
Krydos Posted September 3, 2017 Posted September 3, 2017 (edited) The easiest way to get started with python on a server is with cgi. Really the only difference between cgi and running the script on your home computer is cgi needs to output a content type header.Open file manager https://johnny.heliohost.org:2083/frontend/paper_lantern/filemanager/index.htmlDouble click public_htmlDouble click cgi-binIn the top left click + FileType test.py as your filenameClick Create New FileHighlight the test.py file and click PermissionsCheck execute on all three columns so it says 755Click Change PermissionsClick reload and make sure the 755 shows up under the permissions columnHighlight test.py and click Code EditorLeave UTF-8 as the encoding and click EditCopy/paste this in#!/usr/bin/python3.7 print("Content-Type: text/html\n\n") print("Heliohost rules!") Click Save ChangesGo to http://silverb.heliohost.org/cgi-bin/test.pyIf everything worked it should say "Heliohost rules!" in your browser. The first line is the shebang. That's what tells the server which version of python to use. On Tommy and Johnny you can pick between #!/usr/bin/python2.7 version 2.7.13 #!/usr/bin/python3.7 version 3.7 and python3.6 for Ricky. You can see the modules that are currently installed on the Johnny python versions athttps://krydos2.heliohost.org/cgi-bin/modules27.pyhttps://krydos2.heliohost.org/cgi-bin/modules37.pyIf you don't see the module you need your script will probably give a useless 500 error when you try to import the missing module. Just make a post here on the forums stating your server, the version of python you're using, and the module you need. The next line is the content type header. This is important so the server knows what to do with the output that follows. If you forget it your script will give a useless 500 error. The content type header always has to have the two end lines immediately after it. That's what the \n\n is. Let us know if you have any other questions. Edited July 2, 2020 by Krydos johnny no longer has python2.6 1
silverx Posted September 3, 2017 Author Posted September 3, 2017 Thank you very much. You were a great help. As expected, my script trows a 500 internal error, while yours works fine. I'll open a module request post. Thanks again
Recommended Posts