CGI code not working: Internal Server 500 - python

I am newbie to Apache, and I am trying to move one web application (which is html and python scripts) from one server to another. There is the html file which is calling the python script, and I had placed the cg-bin folder in the www folder, so when I lunch the HTML which calls the python script, then it will generate 500 Internal Server Error.
Any support?
Thanks in advance for your support,

Related

Python Script as Web page

I have a python notebook script; here I have a hard-coded text which I process and display as a tabular format.
What I am looking is to host this my local web so that others too can access this via their PC.
Need help/suggestions.
Flask =) http://flask.pocoo.org/. And locally hosting I use WAMP.

How to Call API written in Python using HTML or PHP [duplicate]

This question already has answers here:
Are a WSGI server and HTTP server required to serve a Flask app?
(3 answers)
Closed 4 years ago.
I'm new to backend and I've written a python script which imports libraries like Flask, sqlalchemy. From taking help from here and there I've been successfully able to get JSON as response to a get call using localhost or http://127.0.0.1/.
Now that this is done I want to take this action on a live server so right now I've hostgator and I've created a folder there so it'll be like mydomain.com/api/. Now my questions is that do I need to place an index.html in this folder which makes a call to run myscript.py or I can directly call mydomain.com/api/myscript.py and it'll return the JSON?
My script is basically a recommendation model that returns recommendations to users upon request.
It's possible to make a request via PHP with the curl_* functions, or you can do the same in JavaScript (e.g. within your HTML file) using AJAX (XMLHttpRequest).
If you are using Flask in your Python script, it is meant to work where the Python program runs all the time, and people's browsers connect to it. It is not mean to work where you put it in a folder and Hostgator's web server invokes it when requests come in; for that you would use the CGI module instead.
If you are buying a server from HostGator, you can log in to the server over SSH and run your script from the command line. Then you would navigate to your server's IP address or domain name in a browser to see if it works, and then you would work out a way to get your app to run all the time, and not just while you are connected and running it manually.
If you are buying just web hosting from HostGator, on the other hand, you may have bought the wrong service. You need access to a computer that can run your Flask app all the time, not just a folder that is served to the web for you.

Running a python script on my hosting

I am a newbie to web development and Python. Since I dont have the vocabulary to ask the exact question, here is a summary of what need to do:
I have a small test python cgi script, which i have uploaded to /home/username/pyscripts which is above the /home/username/domain.com
I need a link I can type in the URL bar, which will lead to the script being executed and the content displayed in the browser.
Can someone tell me If i need to create an html file, and if yes how to get it to point to the python script The domain folder has wordpress installed. My hosting is dreamhost shared hosting
The script is there below:
#! /usr/bin/python
print 'Content-type: text/html'
print ''
print 'Hello, World!
Heroku is a good place to host and python scripts.
Pre-req
pythonscripts.py
procfile
requirements.txt
and After add, commit and push the scripts to heroku app. Just run the following command on terminal to run the scripts.
heroku run python your_scripts.py
More if you want to run this scripts on a schedule timing. then heroku provides lots of adds-on. just search it on heroku
Usually you'd need to put your python script under the /home/username/bin/ folder. I'm not sure if your particular webhost actually allows you to run your Python script outside of the /bin folder (normally this is not the case), but if yes then you can substitute the /pyscripts folder.
The URL would look something like this: www.domain.com/bin/mypythonscript.py
Or with the pyscripts folder (if possible with your webhost): www.domain.com/pyscripts/mypythonscript.py
You don't need to create an HTML file as the first content line that you print in your Python script is telling the user's browser to display the output of the script like an HTML file. You simply type the URL to your python script into your browser and then the server runs the script and outputs it as a text/HTML file, which your browser then reads and displays.
Also, don't forget - you need to grant execute/read/write permission to your Python script file after you upload it to the correct folder on your webhost server or it won't run at all. Usually this is done through your upload utility like Filezilla or using a shell command like chmod.
Well dream host support python. Check if they are providing shell access deployment. All you need is create .py file and run it.
Then consider to use Django or Jinja2 like framwork. Its easy for creating web application

Python with xampp

I want to create a .py file and display simple html code, just like I simply open any php file. I've put file.py inside of the c:/xampp/cgi-bin directory, I've enagled .py extension in apache configs, but...am I doing this the right way? What next?
How to open this file? localhost/cgi-bin/file.py displays the internal server 500 error with the note "Apache/2.4.2 (Win32) OpenSSL/1.0.1c PHP/5.4.4" at the bottom.
you need Choose a web framework. CherryPy. Pylons. Django.

Remote server: running a Python 2.7 script and making *.csv files publicly available

I have a Python 2.7 script that produces *.csv files. I'd like to run this Python script on a remote server and make the *.csv files publicly available to read.
Can this be done on Heroku? I've gone through the tutorial, but it seems to be geared towards people who want to create a whole web site.
If Heroku isn't the solution for me, what are the alternatives? I tried Google App Engine, but it requires Python 2.5 and won't work with 2.7.
MORE DETAILS:
I have a Python 2.7 script that analyzes all stocks that trade on the AMEX, NYSE, and NASDAQ exchanges and writes the output into *.csv files that can be read with a spreadsheet application. I want the script to automatically run every night on a remote server, and I want the *.csv files it produces to be publicly available.
Web hosting
Ok so you should be able to achieve what you need pretty simply. There are many webhosts that have python support. Your requirement is pretty simple. Just upload your python scripts to the web server. Then you can schedule a cron job to call your script at a specific time every day. Your script will run as scheduled and should save the csv files in the web servers document root. Keep in mind you don't need to your script to run in the web server, just on the same server. The web server will just serve your static csv files for you once you place them in the webserver's document root.
Desktop with dropbox
Another maybe easier option is take any desktop and schedule your python script to run on it each night you can do this in windows, Linux, Mac. Also install dropbox it gives you 2GB free online storage. Then your scripts just have to save the csv fies to the Dropbox/Public directory. When they do this they will automatically get synced to the dropbox servers and can be accessed through your public url like any other web page on the internet. You get 2GB for free which should be more then enough for a whole bunch of CSV files.

Categories

Resources