Solved

How could I run this python script on my webserver?

Posted on 2011-09-28
4
347 Views
Last Modified: 2013-12-25
I have a web server that can run python scripts, but I have no experience at all with python. I uploaded the file to my server TorBulkExitList.py and I tried calling it in the browser but it's giving me a 500 Internal Server Error. Here's the python script:

https://svn.torproject.org/svn/check/trunk/cgi-bin/TorBulkExitList.py

Is there anything I need to do before I could run this script? Any other alternative, I just need to get a list of the TOR exit IPs. I'm on a Linux/PHP/Apache server btw.
0
Comment
Question by:Bandai2
  • 4
4 Comments
 
LVL 16

Expert Comment

by:gelonida
ID: 36718068
Hm strange I thought, that I replied already, but perhaps I forgot to submit my message.


First question:
Hopw is your server configured to run python scripts?
- via CGI
- via mod_python
- via mod_wsgi

search your apache config for cgi / python/  wsgi and paste us the relevant lines.

Second question:
- does your script have execute permissions.
To be sure make chmod a+rx yourscriptname.py

Third question:
Did you ever run any python script successfully on your server.
If yoes could you show me the first few lines of the that script?


If your script is a cgi script, and you're running on linux, then make sure,
that the script starts with the line

#!/usr/bin python

The line
#!/usr/bin/env python
does normally not work for cgi scripts.



0
 
LVL 16

Expert Comment

by:gelonida
ID: 36718095
Aplogies,

I didn't look at your python script.

It seems you're using mod_wsgi

(You can recognize this as your python code just declares function and wouldn't execute anything standalone.

One can also see a function named 'application()'

This is the entrypoint of a wsgi application.
0
 
LVL 16

Expert Comment

by:gelonida
ID: 36718112
You could make a very first test with following attached wsgi 'hello world' application

Found on http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide
def application(environ, start_response):
    status = '200 OK'
    output = 'Hello World!'

    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    return [output]

Open in new window

0
 
LVL 16

Accepted Solution

by:
gelonida earned 500 total points
ID: 36718178
Look at your apache config file

You had to add an entry of the kind

WSGIScriptAlias /TorBulkExitList /usr/local/www/mypath/TorBulkExitList.py

You should not put wsgi python scripts in a /cgi-bin url

CGI and WSGI are two incompatible ways of embedding python in a web server
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

A set of related code is known to be a Module, it helps us to organize our code logically which is much easier for us to understand and use it. Module is an object with arbitrarily named attributes which can be used in binding and referencing. …
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now