How to run simple python script on web [closed] - python

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
What is the simplest way of running a python script on the web?
I've been learning to use python to create really simple scripts that scrape the web and represent that data as HTML that can be cut-and-pasted into our CMS.
I'd like to share the technology with my colleagues without forcing them to install python on their machines and thought the web would be a great solution.
I've seen solutions ranging from Django to Flask, Tornado to Python On Wheels but I'm just getting overwhelmed by lots of server-speak.
Can anyone suggest a framework that makes it simple for newbies to get started and develop as I get more experience?
Secondary question: how easy - or not - would it be to have modules available to bolster the toolkit?

Have you considered trying Google App Engine. Some details here: https://developers.google.com/appengine/docs/python/

If you are only interested in scraping maybe scraperwiki is something for you. It allows you to build scrapers in python and it handles the storage.
And otherwise maybe this question has the answer.

You can set it up in apache with WSGI quite easily.. although not sure which OS you're runnin on the server.
For Ubuntu 12.04:
First, install Apache's module:
sudo aptitude install libapache2-mod-wsgi
Then, restart Apache:
sudo service apache2 restart
Then you can add a simple example program to test; install it in /usr/lib/cgi-bin/ then, just run from http://your-domain/cgi-bin/your-script.py
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
print "Content-Type: text/html" # needed to indicate that the content is HTML
print # blank line, end of headers, don't remove
print "Hello World!"
Hope that helps!

Related

Python not working in web browser [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am not able to execute python files in web browser but file can be executed from SHELL terminal.
For Example:
I have created a file under public_html/index.py with following code
#!/home/explore/bin/python
print "Content-Type: text/html\n"
print "Hello World!"
But when I am opening this file in browser, its just coming in simple TEXT.
Note: The index.py file is working fine, When I am trying to run this file by giving absolute path for both files in SHELL terminal using following command
Error: /home/explore/bin/python index.py This gives me error file not found
Correct: /home/explore/bin/python /home/explore/public_html/index.py Works nicely in shell terminal
Please Help, and tell what should i do?
it's normal. The browser don't understand your python file. A browser can handle JavaScript, HTML, ... but no python files. This is why you will have plaintext file.
You need to create an HTTP server that will handle the python file.
You can check around: apache2 and mod_python, django (which is a framework written in python).
Another way would be to write your own HTTP Server in python and connect to it through the browser.
Then you can implement whatever you like. Try to do it by searching : "Python http server" in goodle. There is million of tutorials and guides on the web for that.
Have a nice day.
Kursion
Ressources:
Django guides:
https://docs.djangoproject.com/en/dev/intro/install/
http://hackercodex.com/guide/python-install-django-on-mac-osx-lion-10.7/
http://mirkobonadei.wordpress.com/2010/01/25/install-python-and-django-on-windows/
and so on

Setting up local environment for Python [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I'm trying to transfer from using PHP to Python, Im looking to change to Python as it seems a much more versatile language able to work across a range of scenarios. The sort of things i plan to use it for range from web app development (using django), NLP, machine learning and automation using mechanize.
One of the things I really liked about PHP was MAMP, the way it creates an htdocs folder, a localhost:8888 url, and a MySQL server, with pretty much 0 effort.
Is there something similar with Python ? I'm not necessarily looking for a GUI like MAMP (although that would be good) - what are the other options for setting up a local environment?
Python excels in this area, but as with most tools exactly what you do depends on what you want. In particular, you certainly want virtualenv, Python's configuration and dependency -isolation tool.
You may also want a development-configuration management tool such as buildout, but that is more controversial as there are many other great, language-agnostic tools that overlap. (For example, you may want to set up your environment using Vagrant and leave your host OS behind.)
Neither virtualenv nor buildout will set up Apache for you OotB, but you do have the option of installing django, zope, or many other Python frameworks and applications with buildout recipes. There are recipes for apache too, but most Python web development that I know of is agnostic of the httpd, so you might end up not wanting it.

Why my Django server not work suddenly? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I am woking on Ubuntu 12, python2.6 and Django1.2.x which is my test server.
And I run a Django project on my test server using below command:
python manage.py runserver 0.0.0.0:8000
The server can work for most time(I let it run on 7X24 for other teammate to access it), but sometime it would suddenly not work:
Browser shows me that "server not available" when I try to access it.
And of course, the test server cannot get any request from my frontend, and no error throws on server side.
All will back to OK once I using my django project and run it again.
now I have 2 question:
Why does this issue happend?
How can I develop a shell script to detect this situation?
Actually, it looks like you're trying to use Django development for production purposes. There may be a lot of explanations, like apparmor config, or limitation of single-threaded server, but the problem doesn't worth investigating. Just install Apache2, or Nginx, or uwsgi, and that's it, you have good and stable server without shell watchdogs and other kludges. It would probably take about the same time as posting to SO

Does any webhosting service that supports python also supports django? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I'm trying to learn python/django, these are installed on my desktop computer and all the examples run fine. My question is: If a webhosting service supports python (2.4), does the webhosting service supports django by default?
Thanks guys.
You can use Google App Engine, which is free and includes Django.
Yes, but if they only support Python via CGI then your application will be very, very slow. Best is WSGI, then FastCGI, then mod_python.
Not necessarily.Many web hosting companies(shared) claim to offer django but this is a big lie.Case in point,a2hosting claims to have django but don't offer it;its disallowed.I tried to compile my own python and install django and found out that that path is also closed.
Django is memory intensive and will only work on vps and dedicated accounts.Web faction though is the only web host that wont lie to you.
Try Fornex VPS. https://fornex.com/vds/
I use it and like very much. Month payment starts from 5 euros. And you can install apache 2 + wsgi.

What Web/application servers to use for Python [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I would like to start writing Python web apps, first start simple like servlets in Java, then move to some web frameworks.
What server could I use to develop the apps? Is there a Tomcat version for Python? Is Apache with mod_python the way to go or something else?
I would like to know some options that may help with:
Python based local web development in my own laptop/ PC.
Creating production ready Python web applications.
Thank you!
PS: It is for Python 2.6.5, if that makes a difference
Tomcat is as far as I know only for Java.
You could use the Django-Framework. It has a integrated developmentserver and you can use Apache for a productive enviroment. But i recommend mod_wsgi instead of mod_python.
Here is an example for an wsgi application with apache and django:
# Apache Config
<VirtualHost *>
ServerName example.com
WSGIScriptAlias / /var/www/example/site.wsgi
ErrorLog /var/log/apache2/error.log
</VirtualHost>
# site.wsgi
import os
import sys
sys.path.append( rel(".") )
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
I realize this question was posted a long time ago, but Zope would be an alternative
http://www.zope.org/
There is Django. I guess this could do the job.
Here is a good overview about this.
CherryPy http://www.cherrypy.org/
Google AppEngine appengine.google.com
Apache mod_py apache.org
lighthttp must also have python
support lighthttp.org
I would highly suggest learning Twisted. It makes webservers easy. It is an asynchronous framework the relies on the idea of callbacks. You set up a server. You define how the server responds to different inputs. And then as it receives data it will call the proper methods to handle each incoming request. the twisted.web http module is also very robust yet easy to step into. Great place to start.
See: the following

Categories