Solved

How could I run this python script on my webserver?

Posted on 2011-09-28
4
365 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Easy, flexible multimedia distribution & control

Coming soon!  Ideal for large-scale A/V applications, ATEN's VM3200 Modular Matrix Switch is an all-in-one solution that simplifies video wall integration. Easily customize display layouts to see what you want, how you want it in 4k.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
Dictionaries contain key:value pairs. Which means a collection of tuples with an attribute name and an assigned value to it. The semicolon present in between each key and values and attribute with values are delimited with a comma.  In python we can…
The viewer will learn how to count occurrences of each item in an array.
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…

763 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