Jump to content

[Solved] Total Beginner - Need Help Running A Python Script


Recommended Posts

Posted

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 :)

Posted (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.html
  • Double click public_html
  • Double click cgi-bin
  • In the top left click + File
  • Type test.py as your filename
  • Click Create New File
  • Highlight the test.py file and click Permissions
  • Check execute on all three columns so it says 755
  • Click Change Permissions
  • Click reload and make sure the 755 shows up under the permissions column
  • Highlight test.py and click Code Editor
  • Leave UTF-8 as the encoding and click Edit
  • Copy/paste this in

    #!/usr/bin/python3.7
    
    print("Content-Type: text/html\n\n")
    
    print("Heliohost rules!")
    
  • Click Save Changes
  • Go to http://silverb.heliohost.org/cgi-bin/test.py
If 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 at

https://krydos2.heliohost.org/cgi-bin/modules27.py

https://krydos2.heliohost.org/cgi-bin/modules37.py

If 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 by Krydos
johnny no longer has python2.6
  • Like 1
Posted

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 ^_^

Guest
This topic is now closed to further replies.
×
×
  • Create New...